Imports System.IO
Imports System.Data.SqlClient
Imports System
Imports System.Text
Imports System.Data.Odbc
Public Class FrmPresentationView
    Public GV_ISEDIT As Boolean = False
    Dim ErrorProvider1 As System.Windows.Forms.ErrorProvider
    Dim DSNEvent As DataSet
    Dim DSNInvestigation As DataSet
    Dim DSNHistory As DataSet
    Dim DSNHistology As DataSet
    Dim DSNTxRecommendation As DataSet
    Dim DSNPatient As DataSet
    Dim maxrows As Integer
    Dim inc As Integer
    Dim currentInvestigationID As String
    Dim currentHistoryID As String
    Dim currentHistologyID As String
    Dim currentEventID As String
    Dim currentTxID As String
    Dim currentNeoadjID As String


    Private Sub Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel2.Paint

    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
        'FrmDiagnosis.Text = "Login User: " & GV_USERNAME & "    /  Data Entry - " & GV_CUR_PATNRIC & ", " & GV_CUR_PATNAME
        'FrmDiagnosis.Close()
        'FrmDiagnosis.Show()
        'FrmDiagnosis.Focus()
    End Sub

    Private Sub ClearText()
        txtTumourSize.Text = ""
        cbxExtChestWall.SelectedIndex = -1
        cbxClinAxillaryLN.SelectedIndex = -1

        cbxTypeBiopsy.SelectedIndex = -1
        dtDateBiopsy.Value = "01/01/1900"
        cbxHistoDx.SelectedIndex = -1
        DtPrisurg.Value = "01/01/1900"
        cbxTypeSurg.SelectedIndex = -1
        cbxReconstruction.SelectedIndex = -1

        cboxNeoadjuvant.Checked = False
        cboxLocalRec.Checked = False
        cboxSystemic.Checked = False

        txtPhysicalNotes.Text = ""
        txtHistoNotes.Text = ""

        txtHisto_TumourSize.Text = ""
        cbxHistoType.SelectedIndex = -1
        cbxHistoGrade.SelectedIndex = -1
        cbxDCIS.SelectedIndex = -1
        cbxLymhovascular.SelectedIndex = -1
        cbxMargin_invasive.SelectedIndex = -1
        cboxMarginDCIS.SelectedIndex = -1
        cbxradialMargin.SelectedIndex = -1
        txtRadialMargin.Text = ""
        txtDeepMargin.Text = ""
        cbxSentinel_LN.SelectedIndex = -1
        txtTotal_Ax_LN_Postive.Text = ""
        txtTotal_Ax_LN_Found.Text = ""
        cbxER_Status.SelectedIndex = -1
        cbxPR_Status.SelectedIndex = -1
        cbxErbB2.SelectedIndex = -1

        cbxcT_Status.Text = ""
        cbxN_Status.Text = ""
        cbxM_Status.Text = ""

    End Sub
    Private Sub ClearAllFields()
        GV_SELECTED_NEOADJID = ""
        GV_SELECTED_EVENTID = ""
        GV_SELECTED_HISTOLOGYID = ""
        GV_CUR_PATID = ""
        DateTimePicker1.Text = ""
        cbxDoctor.Text = ""
        CbxCaseType.Text = ""
        CbxLaterality.Text = ""
        cboxMeta.Text = ""
        PatName.Text = ""
        PatNRIC.Text = ""
        lblAge.Text = ""

        Lbl_EnBy.Text = ""
        Lbl_UpdBy.Text = ""
        Lbl_LockBy.Text = ""
        Lbl_EnBy.Visible = True
        Lbl_UpdBy.Visible = True
        Lbl_LockBy.Visible = True

        cbxCXR.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CXR")
        cbxCT.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CT")
        cbxBone.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("BoneScan")
        RichTextNotes.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("Notes")
        cbxCXR.Enabled = False
        cbxCT.Enabled = False
        cbxBone.Enabled = False
        RichTextNotes.Enabled = False

        cbxHistory.Text = "" 'DSNHistory.Tables("dtHistory").Rows(inc).Item("FamilyHistory")
        cbxStatus.Text = "" ' DSNHistory.Tables("dtHistory").Rows(inc).Item("Menstrual")

        cbxHistory.Enabled = False
        cbxStatus.Enabled = False

        txtTumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_tum_size")
        cbxExtChestWall.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("Ext_cw")
        cbxClinAxillaryLN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_ax_ln")
        cbxTypeBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("biopsy_Type")
        dtDateBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_biopsy")
        cbxHistoDx.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_Dx")
        DtPrisurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_pri_surg")
        cbxTypeSurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("surg_type")
        cbxReconstruction.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("reconstruction")
        cboxNeoadjuvant.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
        cboxLocalRec.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
        cboxSystemic.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
        txtPhysicalNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("add_physurg_notes")
        txtHistoNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("other_histo_notes")
        txtHisto_TumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_tum_size")
        cbxHistoType.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_type")
        cbxHistoGrade.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_grade")
        cbxDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ass_dcis")
        cbxLymhovascular.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("lymphovas_inv")
        cbxMargin_invasive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_inv_ca")
        cboxMarginDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_dcis")
        cbxradialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg")
        txtRadialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg_size")
        txtDeepMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("deep_marg_size")
        cbxSentinel_LN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("SLN_1")
        txtTotal_Ax_LN_Postive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_pos")
        txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))
        cbxER_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("er_status")
        cbxPR_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("pr_status")
        cbxErbB2.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("c_erbb2_status")
        cbxcT_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("t_stage_6")
        cbxN_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("n_stage_6")
        cbxM_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("m_stage_6")
        txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
        cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
        cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
        cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
        dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
        cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
        DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
        cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
        cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
        cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
        cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
        cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
        txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
        txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
        txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
        cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
        cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
        cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
        cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
        cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
        cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
        cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
        txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
        txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
        cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
        txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
        txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

        'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
        cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
        cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
        cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
        cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
        cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
        cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

        cbxBTBRecommend.Text = ""
        cboxChemo.Checked = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
        cboxHormonal.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
        cboxRadio.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
        cboxSurgery.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
        cboxTargerted.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
        cboxComplete.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
        txtComments.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
        txtNotes.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

        cbxBTBRecommend.Enabled = False
        cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
        cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
        cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
        cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
        cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
        cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
        txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
        txtNotes.Enabled = False


        cbxSentinelLNPolarity.Enabled = False
        cbxSentinelLNPolarity.Text = ""
    End Sub
    Private Sub LoadTypeSurg()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  124", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxTypeSurg.DataSource = list
            Me.cbxTypeSurg.DisplayMember = "Code_desc"
            Me.cbxTypeSurg.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadBTB_Recommend()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 306", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxBTBRecommend.DataSource = list
            Me.cbxBTBRecommend.DisplayMember = "code_desc"
            Me.cbxBTBRecommend.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadReconstruction()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  544", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxReconstruction.DataSource = list
            Me.cbxReconstruction.DisplayMember = "Code_desc"
            Me.cbxReconstruction.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadHistoDx()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  118", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoDx.DataSource = list
            Me.cbxHistoDx.DisplayMember = "code_desc"
            Me.cbxHistoDx.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadTypeBiopsy()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  112", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxTypeBiopsy.DataSource = list
            Me.cbxTypeBiopsy.DisplayMember = "code_desc"
            Me.cbxTypeBiopsy.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadClinAxillaryLN()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  107", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxClinAxillaryLN.DataSource = list
            Me.cbxClinAxillaryLN.DisplayMember = "code_desc"
            Me.cbxClinAxillaryLN.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadExtChestWall()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  103", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_Desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_Desc")), "", objReader("Code_Desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxExtChestWall.DataSource = list
            Me.cbxExtChestWall.DisplayMember = "Code_Desc"
            Me.cbxExtChestWall.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
        GV_ISEDIT = False

        Panel2.Enabled = True
        btnEdit.Visible = False
        btnDel.Visible = False
        BtnAdd.Visible = False
        btnSave.Visible = True
        btnCancel.Visible = False
        ClearText()

        Button2.Visible = False
        Button3.Visible = False
    End Sub

    Private Sub FrmHistology_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Lbl_EnBy.Visible = False
        Lbl_UpdBy.Visible = False
        Lbl_LockBy.Visible = False

        BtnLock.Visible = False

        GV_SELECTED_HISTOLOGYID = ""
        'BindingNavigator1.BindingSource = Me.BindingSource1
        'Me.BindingNavigator1.Dock = DockStyle.Top
        'Me.Controls.Add(Me.BindingNavigator1)

        'Me.txtDateFirstConsult.Dock = DockStyle.Bottom
        'Me.Controls.Add(Me.txtDateFirstConsult)

        'Panel2.Enabled = False
        'dtDateBiopsy.Value = "01/01/1900"
        'DtPrisurg.Value = "01/01/1900"
        'LoadExtChestWall()
        'LoadClinAxillaryLN()
        'LoadTypeBiopsy()
        'LoadHistoDx()
        'LoadTypeSurg()
        'LoadReconstruction()
        'LoadHistoType()
        'LoadHistoGrade()
        'LoadDCIS()
        'LoadLymhovascular()
        'LoadMargin_invasive()
        'LoadMarginDCIS()
        'LoadRadialMargin()
        'LoadSentinel_LN()
        'LoadER_Status()
        'LoadPR_Status()
        'LoadErbB2()
        'LoadN_Status()
        'LoadM_Status()
        'LoadcT_Status()


        'EVENT table: loaddoctor(), loadcasetype(), loadlaterality()
        LoadDoctor()
        LoadCaseType()
        LoadLaterality()
        'LoadMetasynchronous()

        'HISTOLOGY table: LoadExtChestWall(), LoadClinAxillaryLN(), LoadTypeBiopsy() ,  LoadHistoDx(), LoadTypeSurg(), LoadReconstruction(),
        'LoadHistoType(), LoadHistoGrade(), LoadDCIS(), LoadLymhovascular(),LoadMargin_invasive() ,LoadMarginDCIS(), LoadRadialMargin(), LoadSentinel_LN()
        'LoadER_Status(),  LoadPR_Status(), LoadErbB2(), LoadN_Status(), LoadM_Status(), LoadcT_Status()

        LoadExtChestWall()
        LoadClinAxillaryLN()
        LoadTypeBiopsy()
        LoadHistoDx()
        LoadTypeSurg()
        LoadReconstruction()
        LoadHistoType()
        LoadHistoGrade()
        LoadDCIS()
        LoadLymhovascular()
        LoadMargin_invasive()
        LoadMarginDCIS()
        LoadRadialMargin()
        LoadSentinel_LN()
        LoadER_Status()
        LoadPR_Status()
        LoadErbB2()
        LoadN_Status()
        LoadM_Status()
        LoadcT_Status()
        LoadCXR()
        LoadCT()
        LoadBone()
        LoadFamilyHistory()
        LoadMenstrualStatus()
        LoadBTB_Recommend()
        LoadSentinelLNPolarity()
        'If GV_SELECTED_HISTOLOGYID <> "" Then
        '    ListHistology(GV_SELECTED_HISTOLOGYID)
        '    If GV_FRMEVENT_ALLOW_EDIT = True Then btnEdit_Click(sender, e)
        'End If

        ''added by cherwei to test if this form shld be locked or unlocked for current event
        'If Approved() = True Then
        '    'Button2.Enabled = False
        '    'Button3.Enabled = False
        'Else
        '    'Button2.Enabled = True
        '    'Button3.Enabled = True
        'End If

        'Panel1.Enabled = GV_FRMEVENT_ALLOW_EDIT

        'If Approved() = True Then
        '    'btnAdd.Enabled = False
        '    'btnEdit.Enabled = False
        '    'btnDel.Enabled = False
        '    'Panel1.Enabled = False
        '    'Panel2.Enabled = False
        '    btnEdit.Enabled = False
        '    btnSave.Enabled = False
        '    BtnLock.Text = "Unlock"
        '    btnDel.Enabled = False

        'End If

        'If (GV_FRMEVENT_ALLOW_EDIT) Then 'added by cherwei

        'End If

        'btnDel.Visible = False
        'btnCancel.Visible = False
        'btnEdit.Visible = False



    End Sub

    Private Sub LoadSentinelLNPolarity()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  548", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxSentinelLNPolarity.DataSource = list
            Me.cbxSentinelLNPolarity.DisplayMember = "Code_desc"
            Me.cbxSentinelLNPolarity.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()

    End Sub

    Private Sub LoadMenstrualStatus()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 1", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxStatus.DataSource = list
            Me.cbxStatus.DisplayMember = "code_desc"
            Me.cbxStatus.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadBone()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  8", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxBone.DataSource = list
            Me.cbxBone.DisplayMember = "code_desc"
            Me.cbxBone.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadCXR()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  5", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxCXR.DataSource = list
            Me.cbxCXR.DisplayMember = "Code_desc"
            Me.cbxCXR.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadCT()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  6", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxCT.DataSource = list
            Me.cbxCT.DisplayMember = "code_desc"
            Me.cbxCT.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Function Approved() As Boolean
        Dim vStatus As String = ""
        Dim vLockBy As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select * from Histology where Histo_ID = '" & GV_SELECTED_HISTOLOGYID & "' and event_id = '" & lblEvent.Text & "'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                vStatus = IIf(IsDBNull(objReader("Status")), "", objReader("Status"))
                vLockBy = IIf(IsDBNull(objReader("LockedBy")), "", objReader("LockedBy"))
            Loop

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
        If vLockBy <> "" Then
            Approved = True
            btnSave.Enabled = False
            BtnLock.Visible = False
        Else
            Approved = False
            btnSave.Enabled = True
            BtnLock.Visible = False
        End If

        DateTimePicker1.Enabled = True
        BtnAdd.Enabled = True
    End Function
    Private Sub LoadM_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 207", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxM_Status.DataSource = list
            Me.cbxM_Status.DisplayMember = "Code_desc"
            Me.cbxM_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadN_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 200", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxN_Status.DataSource = list
            Me.cbxN_Status.DisplayMember = "Code_desc"
            Me.cbxN_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadErbB2()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 183", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxErbB2.DataSource = list
            Me.cbxErbB2.DisplayMember = "Code_desc"
            Me.cbxErbB2.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadPR_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 178", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxPR_Status.DataSource = list
            Me.cbxPR_Status.DisplayMember = "Code_desc"
            Me.cbxPR_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadER_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 173", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxER_Status.DataSource = list
            Me.cbxER_Status.DisplayMember = "Code_desc"
            Me.cbxER_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadSentinel_LN()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  547", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxSentinel_LN.DataSource = list
            Me.cbxSentinel_LN.DisplayMember = "Code_desc"
            Me.cbxSentinel_LN.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadRadialMargin()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  165", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxradialMargin.DataSource = list
            Me.cbxradialMargin.DisplayMember = "Code_desc"
            Me.cbxradialMargin.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadMarginDCIS()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  162", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cboxMarginDCIS.DataSource = list
            Me.cboxMarginDCIS.DisplayMember = "Code_desc"
            Me.cboxMarginDCIS.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadMargin_invasive()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  159", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxMargin_invasive.DataSource = list
            Me.cbxMargin_invasive.DisplayMember = "Code_desc"
            Me.cbxMargin_invasive.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadLymhovascular()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  154", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxLymhovascular.DataSource = list
            Me.cbxLymhovascular.DisplayMember = "Code_desc"
            Me.cbxLymhovascular.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadDCIS()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  260", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_Desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_Desc")), "", objReader("Code_Desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxDCIS.DataSource = list
            Me.cbxDCIS.DisplayMember = "Code_Desc"
            Me.cbxDCIS.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadcT_Status()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 274", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxcT_Status.DataSource = list
            Me.cbxcT_Status.DisplayMember = "Code_desc"
            Me.cbxcT_Status.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub LoadHistoGrade()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  149", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("Code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("Code_desc")), "", objReader("Code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoGrade.DataSource = list
            Me.cbxHistoGrade.DisplayMember = "Code_desc"
            Me.cbxHistoGrade.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadHistoType()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  132", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("Code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Code")), "", objReader("Code"))
                i = i + 1
            Loop
            Me.cbxHistoType.DataSource = list
            Me.cbxHistoType.DisplayMember = "code_desc"
            Me.cbxHistoType.ValueMember = "Code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub
    Private Sub ListHistology(ByVal vHistoID)


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select * from Histology where Histo_id = '" & vHistoID & "'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                txtTumourSize.Text = IIf(IsDBNull(objReader("clin_tum_size")), "", objReader("clin_tum_size"))
                cbxExtChestWall.Text = IIf(IsDBNull(objReader("Ext_cw")), "", objReader("Ext_cw"))
                cbxClinAxillaryLN.Text = IIf(IsDBNull(objReader("clin_ax_ln")), "", objReader("clin_ax_ln"))
                cbxTypeBiopsy.Text = IIf(IsDBNull(objReader("biopsy_Type")), "", objReader("biopsy_Type"))
                dtDateBiopsy.Value = IIf(IsDBNull(objReader("date_biopsy")), "01/01/1900", objReader("date_biopsy"))
                cbxHistoDx.Text = IIf(IsDBNull(objReader("histo_Dx")), "", objReader("histo_Dx"))
                DtPrisurg.Value = IIf(IsDBNull(objReader("date_pri_surg")), "01/01/1900", objReader("date_pri_surg"))
                cbxTypeSurg.Text = IIf(IsDBNull(objReader("surg_type")), "", objReader("surg_type"))
                cbxReconstruction.Text = IIf(IsDBNull(objReader("reconstruction")), "", objReader("reconstruction"))
                cboxNeoadjuvant.Checked = IIf(IsDBNull(objReader("chk_Neoadj")), False, objReader("chk_Neoadj"))
                cboxLocalRec.Checked = IIf(IsDBNull(objReader("chk_Local")), False, objReader("chk_Local"))
                cboxSystemic.Checked = IIf(IsDBNull(objReader("chk_Systemic")), False, objReader("chk_Systemic"))
                txtPhysicalNotes.Text = IIf(IsDBNull(objReader("add_physurg_notes")), "", objReader("add_physurg_notes"))
                txtHistoNotes.Text = IIf(IsDBNull(objReader("other_histo_notes")), "", objReader("other_histo_notes"))
                txtHisto_TumourSize.Text = IIf(IsDBNull(objReader("histo_tum_size")), "", objReader("histo_tum_size"))
                cbxHistoType.Text = IIf(IsDBNull(objReader("histo_type")), "", objReader("histo_type"))
                cbxHistoGrade.Text = IIf(IsDBNull(objReader("histo_grade")), "", objReader("histo_grade"))
                cbxDCIS.Text = IIf(IsDBNull(objReader("ass_dcis")), "", objReader("ass_dcis"))
                cbxLymhovascular.Text = IIf(IsDBNull(objReader("lymphovas_inv")), "", objReader("lymphovas_inv"))
                cbxMargin_invasive.Text = IIf(IsDBNull(objReader("marg_inv_ca")), "", objReader("marg_inv_ca"))
                cboxMarginDCIS.Text = IIf(IsDBNull(objReader("marg_dcis")), "", objReader("marg_dcis"))
                cbxradialMargin.Text = IIf(IsDBNull(objReader("closest_marg")), "", objReader("closest_marg"))
                txtRadialMargin.Text = IIf(IsDBNull(objReader("closest_marg_size")), "", objReader("closest_marg_size"))
                txtDeepMargin.Text = IIf(IsDBNull(objReader("deep_marg_size")), "", objReader("deep_marg_size"))
                cbxSentinel_LN.Text = IIf(IsDBNull(objReader("SLN_1")), "", objReader("SLN_1"))
                txtTotal_Ax_LN_Postive.Text = IIf(IsDBNull(objReader("ax_ln_pos")), "", objReader("ax_ln_pos"))
                txtTotal_Ax_LN_Found.Text = IIf(IsDBNull(objReader("ax_ln_fd")), "", objReader("ax_ln_fd"))
                cbxER_Status.Text = IIf(IsDBNull(objReader("er_status")), "", objReader("er_status"))
                cbxPR_Status.Text = IIf(IsDBNull(objReader("pr_status")), "", objReader("pr_status"))
                cbxErbB2.Text = IIf(IsDBNull(objReader("c_erbb2_status")), "", objReader("c_erbb2_status"))
                cbxcT_Status.Text = IIf(IsDBNull(objReader("t_stage_6")), "", objReader("t_stage_6"))
                cbxN_Status.Text = IIf(IsDBNull(objReader("n_stage_6")), "", objReader("n_stage_6"))
                cbxM_Status.Text = IIf(IsDBNull(objReader("m_stage_6")), "", objReader("m_stage_6"))
                Lbl_EnBy.Text = "Entered By:" & vbCrLf & IIf(IsDBNull(objReader("EnteredBy")), "", objReader("EnteredBy"))
                Lbl_UpdBy.Text = "Updated By:" & vbCrLf & IIf(IsDBNull(objReader("UpdatedBy")), "", objReader("UpdatedBy"))
                Lbl_LockBy.Text = "Locked By:" & vbCrLf & IIf(IsDBNull(objReader("LockedBy")), "", objReader("LockedBy"))

            Loop

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        If GV_ISEDIT = False Then ClearText() Else ListHistology(GV_SELECTED_HISTOLOGYID)
        Panel2.Enabled = False
        BtnAdd.Visible = True
        btnEdit.Visible = True
        btnDel.Visible = True
        btnSave.Visible = False
        btnCancel.Visible = False
    End Sub

    Private Sub btnDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDel.Click
        If GV_SELECTED_HISTOLOGYID <> "" Then
            Dim response As Integer

            response = MsgBox("Are you sure want to delete this record?", MsgBoxStyle.YesNo, "Delete")
            If response = 7 Then
                Exit Sub
            End If

            Dim myCommand As SqlCommand
            Dim SqlConn As New SqlConnection()
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spDelHistology", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
            myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
            myCommand.Parameters("@EnteredBy").Value = GV_USER

            myCommand.ExecuteNonQuery()

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing
            Close()
            FrmDiagnosis.Close()
            FrmDiagnosis.Show()
        End If
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        If GV_SELECTED_HISTOLOGYID <> "" Then
            GV_ISEDIT = True
            Panel2.Enabled = True
            btnEdit.Visible = False
            btnDel.Visible = False
            BtnAdd.Visible = False
            btnSave.Visible = True
            btnCancel.Visible = True
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click


        'check if event is locked, enable/disable save button
        If Trim(GV_SELECTED_EVENTID) = "" Then
            btnSave.Enabled = False
            btnCopy.Enabled = False
            Exit Sub
        Else
            btnSave.Enabled = True
            btnCopy.Enabled = True
        End If

        'Perform the save functions
        'save function for event
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertEvent", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@date_tb", SqlDbType.DateTime)
        myCommand.Parameters.Add("@date_cn", SqlDbType.DateTime)
        myCommand.Parameters.Add("@doc_inc", SqlDbType.VarChar)
        myCommand.Parameters.Add("@case_type", SqlDbType.VarChar)
        myCommand.Parameters.Add("@brst_screen", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasyn_Status", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasynchronous", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_Id_old", SqlDbType.VarChar)

        'check n retrieve current eventid on the form, if eventid is empty, gv_isedit = false else gv_isedit = true
        If Trim(lblEvent.Text).IndexOf("E") = -1 Then
            GV_ISEDIT = False
        Else
            GV_ISEDIT = True
        End If

        If GV_ISEDIT = True Then
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        Else
            myCommand.Parameters("@Event_ID").Value = "0"
        End If
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@date_tb").Value = FormatDateTime(DOB.Value, DateFormat.ShortDate)
        myCommand.Parameters("@date_cn").Value = FormatDateTime(DateTimePicker1.Value, DateFormat.ShortDate)
        myCommand.Parameters("@doc_inc").Value = Trim(cbxDoctor.Text)
        myCommand.Parameters("@case_type").Value = Trim(CbxCaseType.Text)
        myCommand.Parameters("@brst_screen").Value = Trim(CbxLaterality.Text)
        myCommand.Parameters("@Metasyn_Status").Value = Trim(cboxMeta.Text)
        myCommand.Parameters("@Metasynchronous").Value = Trim(cboxMetasEvent.SelectedValue)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.Parameters("@Event_Id_old").Value = ""

        'check again, if patient data is in database, do not execute
        Dim vPatID As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select ptNRIC from PATIENTS where ptNRIC = '" & PatNRIC.Text & "'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                vPatID = IIf(IsDBNull(objReader("ptNRIC")), "", objReader("ptNRIC"))
            Loop

        Catch ex As Exception
            MsgBox(ex.Source)
            Exit Sub
        End Try


        If LTrim(RTrim(vPatID)) = "" Then
            MsgBox("Please load an existing event first")
            btnSave.Enabled = False
            sqlCmd.Cancel()
            SqlConnection1.Close()
            sqlCmd = Nothing
            SqlConnection1.Close()
        Else
            myCommand.ExecuteNonQuery()

            ' perform the save procedures to other tables 
            'save function for investigation
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertInvestigation", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@Inv_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@CXR", SqlDbType.VarChar)
            myCommand.Parameters.Add("@CT", SqlDbType.VarChar)
            myCommand.Parameters.Add("@BoneScan", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            If Trim(GV_SELECTED_INVESTID).IndexOf("I") = -1 Then
                GV_ISEDIT = False
            Else
                GV_ISEDIT = True
            End If

            If GV_ISEDIT = True Then
                myCommand.Parameters("@Inv_ID").Value = GV_SELECTED_INVESTID
            Else
                myCommand.Parameters("@Inv_ID").Value = "0"
            End If
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
            myCommand.Parameters("@CXR").Value = Trim(cbxCXR.SelectedValue)
            myCommand.Parameters("@CT").Value = Trim(cbxCT.SelectedValue)
            myCommand.Parameters("@BoneScan").Value = Trim(cbxBone.SelectedValue)
            myCommand.Parameters("@Notes").Value = Trim(RichTextNotes.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER

            If Trim(GV_SELECTED_INVESTID).IndexOf("I") = -1 Then

            Else
                myCommand.ExecuteNonQuery()

            End If

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing


            'save function for tx recommendation details

            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertTxRecommendation", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@recom_id", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@recommendation", SqlDbType.VarChar)
            myCommand.Parameters.Add("@chemotherapy", SqlDbType.Bit)
            myCommand.Parameters.Add("@hormonaltherapy", SqlDbType.Bit)
            myCommand.Parameters.Add("@radiotherapy", SqlDbType.Bit)
            myCommand.Parameters.Add("@surgery", SqlDbType.Bit)
            myCommand.Parameters.Add("@immunotherapy", SqlDbType.Bit)
            myCommand.Parameters.Add("@recommend_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@form_complete", SqlDbType.Bit)
            myCommand.Parameters.Add("@update_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            If Trim(GV_SELECTED_TXID).IndexOf("T") = -1 Then
                GV_ISEDIT = False
            Else
                GV_ISEDIT = True
            End If

            If GV_ISEDIT = True Then
                myCommand.Parameters("@recom_id").Value = GV_SELECTED_TXID
            Else
                myCommand.Parameters("@recom_id").Value = "0"

            End If
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@recommendation").Value = Trim(cbxBTBRecommend.Text)
            myCommand.Parameters("@chemotherapy").Value = cboxChemo.Checked
            myCommand.Parameters("@hormonaltherapy").Value = cboxHormonal.Checked
            myCommand.Parameters("@radiotherapy").Value = cboxRadio.Checked
            myCommand.Parameters("@surgery").Value = cboxSurgery.Checked
            myCommand.Parameters("@immunotherapy").Value = cboxTargerted.Checked
            myCommand.Parameters("@recommend_notes").Value = Trim(txtComments.Text)
            myCommand.Parameters("@form_complete").Value = cboxComplete.Checked
            myCommand.Parameters("@update_notes").Value = Trim(txtNotes.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER
            If Trim(GV_SELECTED_TXID).IndexOf("T") = -1 Then

            Else
                myCommand.ExecuteNonQuery()
            End If

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing


            'save histology table
            Try
                SqlConn = New SqlConnection(GV_CONNETION)
                myCommand = New SqlCommand("spInsertHistology", SqlConn)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn.Open()

                myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
                myCommand.Parameters.Add("@clin_tum_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Ext_cw", SqlDbType.VarChar)
                myCommand.Parameters.Add("@clin_ax_ln", SqlDbType.VarChar)
                myCommand.Parameters.Add("@biopsy_Type", SqlDbType.VarChar)
                myCommand.Parameters.Add("@date_biopsy", SqlDbType.DateTime)
                myCommand.Parameters.Add("@histo_Dx", SqlDbType.VarChar)
                myCommand.Parameters.Add("@date_pri_surg", SqlDbType.DateTime)
                myCommand.Parameters.Add("@surg_type", SqlDbType.VarChar)
                myCommand.Parameters.Add("@reconstruction", SqlDbType.VarChar)
                myCommand.Parameters.Add("@chk_Neoadj", SqlDbType.Bit)
                myCommand.Parameters.Add("@chk_Local", SqlDbType.Bit)
                myCommand.Parameters.Add("@chk_Systemic", SqlDbType.Bit)
                myCommand.Parameters.Add("@add_physurg_notes", SqlDbType.VarChar)
                myCommand.Parameters.Add("@other_histo_notes", SqlDbType.VarChar)
                myCommand.Parameters.Add("@histo_tum_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@histo_type", SqlDbType.VarChar)
                myCommand.Parameters.Add("@histo_grade", SqlDbType.VarChar)
                myCommand.Parameters.Add("@ass_dcis", SqlDbType.VarChar)
                myCommand.Parameters.Add("@lymphovas_inv", SqlDbType.VarChar)
                myCommand.Parameters.Add("@marg_inv_ca", SqlDbType.VarChar)
                myCommand.Parameters.Add("@marg_dcis", SqlDbType.VarChar)
                myCommand.Parameters.Add("@closest_marg", SqlDbType.VarChar)
                myCommand.Parameters.Add("@closest_marg_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@deep_marg_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@SLN_1", SqlDbType.VarChar)
                myCommand.Parameters.Add("@SLN_2", SqlDbType.VarChar)
                myCommand.Parameters.Add("@ax_ln_pos", SqlDbType.VarChar)
                myCommand.Parameters.Add("@ax_ln_fd", SqlDbType.VarChar)
                myCommand.Parameters.Add("@er_status", SqlDbType.VarChar)
                myCommand.Parameters.Add("@pr_status", SqlDbType.VarChar)
                myCommand.Parameters.Add("@c_erbb2_status", SqlDbType.VarChar)
                myCommand.Parameters.Add("@t_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@n_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@m_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

                If Trim(GV_SELECTED_HISTOLOGYID).IndexOf("S") = -1 Then
                    GV_ISEDIT = False
                Else
                    GV_ISEDIT = True
                End If

                If GV_ISEDIT = True Then
                    myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
                Else
                    myCommand.Parameters("@Histo_ID").Value = "0"
                End If
                myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
                myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
                myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
                myCommand.Parameters("@Ext_cw").Value = Trim(cbxExtChestWall.Text)
                myCommand.Parameters("@clin_ax_ln").Value = Trim(cbxClinAxillaryLN.Text)
                myCommand.Parameters("@biopsy_Type").Value = Trim(cbxTypeBiopsy.Text)
                myCommand.Parameters("@date_biopsy").Value = dtDateBiopsy.Value
                myCommand.Parameters("@histo_Dx").Value = Trim(cbxHistoDx.Text)
                myCommand.Parameters("@date_pri_surg").Value = DtPrisurg.Value
                myCommand.Parameters("@surg_type").Value = Trim(cbxTypeSurg.Text)
                myCommand.Parameters("@reconstruction").Value = Trim(cbxReconstruction.Text)
                myCommand.Parameters("@chk_Neoadj").Value = cboxNeoadjuvant.Checked
                myCommand.Parameters("@chk_Local").Value = cboxLocalRec.Checked
                myCommand.Parameters("@chk_Systemic").Value = cboxSystemic.Checked
                myCommand.Parameters("@add_physurg_notes").Value = Trim(txtPhysicalNotes.Text)
                myCommand.Parameters("@other_histo_notes").Value = Trim(txtHistoNotes.Text)
                myCommand.Parameters("@histo_tum_size").Value = Trim(txtHisto_TumourSize.Text)
                myCommand.Parameters("@histo_type").Value = Trim(cbxHistoType.Text)
                myCommand.Parameters("@histo_grade").Value = Trim(cbxHistoGrade.Text)
                myCommand.Parameters("@ass_dcis").Value = Trim(cbxDCIS.Text)
                myCommand.Parameters("@lymphovas_inv").Value = Trim(cbxLymhovascular.Text)
                myCommand.Parameters("@marg_inv_ca").Value = Trim(cbxMargin_invasive.Text)
                myCommand.Parameters("@marg_dcis").Value = Trim(cboxMarginDCIS.Text)
                myCommand.Parameters("@closest_marg").Value = Trim(cbxradialMargin.Text)
                myCommand.Parameters("@closest_marg_size").Value = Trim(txtRadialMargin.Text)
                myCommand.Parameters("@deep_marg_size").Value = Trim(txtDeepMargin.Text)
                myCommand.Parameters("@SLN_1").Value = Trim(cbxSentinel_LN.Text)
                myCommand.Parameters("@SLN_2").Value = Trim(cbxSentinelLNPolarity.Text)
                myCommand.Parameters("@ax_ln_pos").Value = Trim(txtTotal_Ax_LN_Postive.Text)
                myCommand.Parameters("@ax_ln_fd").Value = Trim(txtTotal_Ax_LN_Found.Text)
                myCommand.Parameters("@er_status").Value = Trim(cbxER_Status.Text)
                myCommand.Parameters("@pr_status").Value = Trim(cbxPR_Status.Text)
                myCommand.Parameters("@c_erbb2_status").Value = Trim(cbxErbB2.Text)
                myCommand.Parameters("@t_stage_6").Value = Trim(cbxcT_Status.Text)
                myCommand.Parameters("@n_stage_6").Value = Trim(cbxN_Status.Text)
                myCommand.Parameters("@m_stage_6").Value = Trim(cbxM_Status.Text)
                myCommand.Parameters("@EnteredBy").Value = GV_USER
                If Trim(GV_SELECTED_HISTOLOGYID).IndexOf("S") = -1 Then

                Else
                    myCommand.ExecuteNonQuery()


                End If

                myCommand.Cancel()
                SqlConn.Close()
                myCommand = Nothing
                SqlConn = Nothing
            Catch ex As Exception
                MsgBox(ex.Message)
                Exit Sub
            End Try

            'save history table
            Try
                SqlConn = New SqlConnection(GV_CONNETION)
                myCommand = New SqlCommand("spInsertHistory", SqlConn)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn.Open()

                myCommand.Parameters.Add("@History_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
                myCommand.Parameters.Add("@FamilyHistory", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Menstrual", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

                If Trim(GV_SELECTED_HISTORYID).IndexOf("H") = -1 Then
                    GV_ISEDIT = False
                Else
                    GV_ISEDIT = True
                End If

                If GV_ISEDIT = True Then
                    myCommand.Parameters("@History_ID").Value = GV_SELECTED_HISTORYID
                Else
                    myCommand.Parameters("@History_ID").Value = "0"
                End If
                myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
                myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
                myCommand.Parameters("@FamilyHistory").Value = Trim(cbxHistory.Text)
                myCommand.Parameters("@Menstrual").Value = Trim(cbxStatus.Text)
                myCommand.Parameters("@EnteredBy").Value = GV_USER

                If Trim(GV_SELECTED_HISTORYID).IndexOf("H") = -1 Then

                Else
                    myCommand.ExecuteNonQuery()
                End If

                myCommand.Cancel()
                SqlConn.Close()
                myCommand = Nothing
                SqlConn = Nothing
            Catch ex As Exception
                MsgBox(ex.Message)
                Exit Sub
            End Try

            MsgBox("Event " & GV_SELECTED_EVENTID & " details for patient " & vPatID & " updated")
        End If


        'SqlConn.Close()
        'myCommand = Nothing
        'SqlConn = Nothing



        'If ValidateHistology() = True Then
        'SaveHistology()
        'Panel2.Enabled = False
        'Close()
        'FrmDiagnosis.Close()
        'FrmDiagnosis.Show()
        'FrmDiagnosis.Focus()
        'Else

        'End If

    End Sub
    'validation added by cherwei
    Private Function ValidateHistology() As Boolean
        Dim flag As String
        'Perform necessary validation for the required fields
        flag = 0
        'If (LTrim(RTrim(txtTumourSize.Text)) = "") Or (LTrim(RTrim(txtRadialMargin.Text)) = "") Or (LTrim(RTrim(txtRadialMargin.Text)) = "") Then
        'validation to allow null
        'flag = 0
        'End If
        If (Not IsNumeric(txtTumourSize.Text) Or txtTumourSize.Text.IndexOf(",") <> -1) And Not (LTrim(RTrim(txtTumourSize.Text)) = "") Then
            'Me.ErrorProvider1.SetError(Me.txtTumourSize, "Please Enter numeric values for tumor size")
            MsgBox("Please enter numeric values for tumor size")
            'Throw New Exception("Please enter a numeric value")
            flag = 1
            txtTumourSize.Focus()
            'Else if isnumeric(

        ElseIf (Not IsNumeric(txtHisto_TumourSize.Text.Trim) Or txtHisto_TumourSize.Text.IndexOf(",") <> -1) And Not (LTrim(RTrim(txtHisto_TumourSize.Text)) = "") Then
            MsgBox("Please enter numeric values for histo tumor size")
            'Throw New Exception("Please enter a numeric value")
            flag = 1
            txtHisto_TumourSize.Focus()

        ElseIf (Not IsNumeric(txtRadialMargin.Text.Trim) Or txtRadialMargin.Text.IndexOf(",") <> -1) And Not (LTrim(RTrim(txtRadialMargin.Text)) = "") Then
            MsgBox("Please enter numeric values for radial margin")
            flag = 1
            txtRadialMargin.Focus()

        ElseIf (Not IsNumeric(txtDeepMargin.Text.Trim) Or txtDeepMargin.Text.IndexOf(",") <> -1) And Not (LTrim(RTrim(txtDeepMargin.Text)) = "") Then
            MsgBox("Please enter numeric values for deep margin")
            flag = 1
            txtDeepMargin.Focus()

        End If


        If flag = 0 Then
            ValidateHistology = True 'validation pass
        Else
            ValidateHistology = False 'validation fail
        End If


    End Function

    Private Sub SaveHistology()


        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        Try
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertHistology", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Ext_cw", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_ax_ln", SqlDbType.VarChar)
            myCommand.Parameters.Add("@biopsy_Type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_biopsy", SqlDbType.DateTime)
            myCommand.Parameters.Add("@histo_Dx", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_pri_surg", SqlDbType.DateTime)
            myCommand.Parameters.Add("@surg_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@reconstruction", SqlDbType.VarChar)
            myCommand.Parameters.Add("@chk_Neoadj", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Local", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Systemic", SqlDbType.Bit)
            myCommand.Parameters.Add("@add_physurg_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@other_histo_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_grade", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ass_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@lymphovas_inv", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_inv_ca", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@deep_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_pos", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_fd", SqlDbType.VarChar)
            myCommand.Parameters.Add("@er_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@pr_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@c_erbb2_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@t_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@n_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@m_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            If GV_ISEDIT = True Then
                myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
            Else
                myCommand.Parameters("@Histo_ID").Value = "0"
            End If
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID


            'If Not IsNumeric(txtTumourSize.Text) Then
            'Me.ErrorProvider1.SetError(Me.txtTumourSize, "Please Enter numeric values for tumor size")
            'Throw New Exception("Please enter a numeric value")
            'Else
            'myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
            'End If
            myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
            myCommand.Parameters("@Ext_cw").Value = Trim(cbxExtChestWall.Text)
            myCommand.Parameters("@clin_ax_ln").Value = Trim(cbxClinAxillaryLN.Text)
            myCommand.Parameters("@biopsy_Type").Value = Trim(cbxTypeBiopsy.Text)
            myCommand.Parameters("@date_biopsy").Value = dtDateBiopsy.Value
            myCommand.Parameters("@histo_Dx").Value = Trim(cbxHistoDx.Text)
            myCommand.Parameters("@date_pri_surg").Value = DtPrisurg.Value
            myCommand.Parameters("@surg_type").Value = Trim(cbxTypeSurg.Text)
            myCommand.Parameters("@reconstruction").Value = Trim(cbxReconstruction.Text)
            myCommand.Parameters("@chk_Neoadj").Value = cboxNeoadjuvant.Checked
            myCommand.Parameters("@chk_Local").Value = cboxLocalRec.Checked
            myCommand.Parameters("@chk_Systemic").Value = cboxSystemic.Checked
            myCommand.Parameters("@add_physurg_notes").Value = Trim(txtPhysicalNotes.Text)
            myCommand.Parameters("@other_histo_notes").Value = Trim(txtHistoNotes.Text)
            myCommand.Parameters("@histo_tum_size").Value = Trim(txtHisto_TumourSize.Text)
            myCommand.Parameters("@histo_type").Value = Trim(cbxHistoType.Text)
            myCommand.Parameters("@histo_grade").Value = Trim(cbxHistoGrade.Text)
            myCommand.Parameters("@ass_dcis").Value = Trim(cbxDCIS.Text)
            myCommand.Parameters("@lymphovas_inv").Value = Trim(cbxLymhovascular.Text)
            myCommand.Parameters("@marg_inv_ca").Value = Trim(cbxMargin_invasive.Text)
            myCommand.Parameters("@marg_dcis").Value = Trim(cboxMarginDCIS.Text)
            myCommand.Parameters("@closest_marg").Value = Trim(cbxradialMargin.Text)
            myCommand.Parameters("@closest_marg_size").Value = Trim(txtRadialMargin.Text)
            myCommand.Parameters("@deep_marg_size").Value = Trim(txtDeepMargin.Text)
            myCommand.Parameters("@SLN_1").Value = Trim(cbxSentinel_LN.Text)
            myCommand.Parameters("@ax_ln_pos").Value = Trim(txtTotal_Ax_LN_Postive.Text)
            myCommand.Parameters("@ax_ln_fd").Value = Trim(txtTotal_Ax_LN_Found.Text)
            myCommand.Parameters("@er_status").Value = Trim(cbxER_Status.Text)
            myCommand.Parameters("@pr_status").Value = Trim(cbxPR_Status.Text)
            myCommand.Parameters("@c_erbb2_status").Value = Trim(cbxErbB2.Text)
            myCommand.Parameters("@t_stage_6").Value = Trim(cbxcT_Status.Text)
            myCommand.Parameters("@n_stage_6").Value = Trim(cbxN_Status.Text)
            myCommand.Parameters("@m_stage_6").Value = Trim(cbxM_Status.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER
            myCommand.ExecuteNonQuery()

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        'If GV_SELECTED_HISTOLOGYID = "" Then
        If currentHistologyID = "" Then
            MsgBox("Please create histology first.")
            Exit Sub
        End If



        'validation added by cherwei, if current event is locked, do not allow new neoadj treatments to be added
        'If Approved() = True Then

        Dim vNeoAdj_ID As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        'Dim sqlCmd = New SqlCommand("select Neoadj_id from NEOADJ where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
        Dim sqlCmd = New SqlCommand("select Neoadj_id from NEOADJ where Event_ID = '" & currentEventID & "' and status <> 'D'", SqlConnection1)

        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                vNeoAdj_ID = IIf(IsDBNull(objReader("Neoadj_id")), "", objReader("Neoadj_id"))
                'GV_SELECTED_NEOADJID = vNeoAdj_ID
                currentNeoadjID = vNeoAdj_ID
                lblNeoadj.Text = currentNeoadjID
            Loop

        Catch ex As Exception
            MsgBox(ex.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()

        'If LTrim(RTrim(vNeoAdj_ID)) = "" Then
        'MsgBox("Please unlock event before creating new neoadjuvant details")
        'Else
        '   FrmNeoadjuvant.ShowDialog()
        'End If
        'Else
        'FrmNeoadjuvant.ShowDialog()


        'End If

        FrmNeoadjuvantView.ShowDialog()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'If GV_SELECTED_HISTOLOGYID = "" Then
        If currentHistologyID = "" Then
            MsgBox("Please create histology first.")
            Exit Sub
        End If



        'added by cherwei for validation such that a new prior treatment form cannot be saved if current event is locked
        'validation added by cherwei, if current event is locked, do not allow new neoadj treatments to be added
        If Approved() = True Then

            Dim vNeoAdj_ID As String = ""
            Dim SqlConnection1 As New SqlConnection()
            SqlConnection1 = New SqlConnection(GV_CONNETION)
            If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
            'Dim sqlCmd = New SqlCommand("select priortx_id from priortx where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
            Dim sqlCmd = New SqlCommand("select priortx_id from priortx where Event_ID = '" & currentEventID & "' and status <> 'D'", SqlConnection1)

            Try
                Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
                Do While objReader.Read
                    vNeoAdj_ID = IIf(IsDBNull(objReader("priortx_id")), "", objReader("priortx_id"))
                    lblLocal.Text = vNeoAdj_ID
                Loop

            Catch ex As Exception
                MsgBox(ex.Source)
            End Try

            sqlCmd.Cancel()
            SqlConnection1.Close()
            sqlCmd = Nothing
            SqlConnection1.Close()

            'If LTrim(RTrim(vNeoAdj_ID)) = "" Then
            'MsgBox("Please unlock event before creating new prior treatment record")
            'Exit Sub
            'Else
            'FrmRcdPriorTreatment.ShowDialog()
            'End If
            'Else

        End If


        FrmRcdPriorTreatmentView.ShowDialog()

    End Sub

    Private Sub FrmHistology_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize

    End Sub

    Private Sub BtnLock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLock.Click
        If BtnLock.Text = "Lock" Then
            If GV_FRMEVENT_ALLOW_APPROVE = False Then
                MsgBox("Permission denied.", MsgBoxStyle.Information)
                Exit Sub
            End If
        End If

        If BtnLock.Text = "UnLock" Then
            'FrmApprove.Text = "Unlock Event..." 'added by cherwei on 05May09
            'FrmApprove.ShowDialog()             'added by cherwei on 05May09
            'FrmApprove.TxtPw.Focus()            'added by cherwei on 05MAy09

            If GV_FRMEVENT_ALLOW_APPROVE = False Then
                MsgBox("Permission denied.", MsgBoxStyle.Information)
                Exit Sub
            End If
        End If

        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("sp_LockUnlockHistology", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()
        myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
        myCommand.Parameters.Add("@LockFlag", SqlDbType.VarChar)

        myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        myCommand.Parameters("@LockFlag").Value = Trim(BtnLock.Text)
        myCommand.ExecuteNonQuery()

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing

        If BtnLock.Text = "Lock" Then
            BtnLock.Text = "UnLock"
            btnEdit.Enabled = False
            btnSave.Enabled = False
            btnDel.Enabled = False
            Lbl_LockBy.Text = "Locked By:" & vbCrLf & GV_USERNAME
        Else
            BtnLock.Text = "Lock"
            btnEdit.Enabled = GV_FRMEVENT_ALLOW_EDIT
            btnSave.Enabled = GV_FRMEVENT_ALLOW_EDIT
            btnDel.Enabled = GV_FRMEVENT_ALLOW_EDIT
            Lbl_LockBy.Text = "Locked By:"
        End If

    End Sub

    Private Sub txtPhysicalNotes_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPhysicalNotes.TextChanged      
        Label31.Text = txtPhysicalNotes.Text.Length
        Label31.Text = Label31.Text + "/3000"
    End Sub

    Private Sub txtHistoNotes_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHistoNotes.TextChanged
        Label32.Text = txtHistoNotes.Text.Length
        Label32.Text = Label32.Text + "/3000"
    End Sub


    Public Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        'on button clicked, retrieve btb date from datetimepicker1
        BtnLock.Visible = False
        Dim patientName As String
        Dim patientNRIC As String
        Dim patientAge As String

        Dim count As Integer
        'Load from event table
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        'Dim datetimepickertext As String = DateTimePicker1.Text.ToString()
        Dim currentDOBtext As String = DOB.Text.ToString
        'Dim DAEvent As New SqlClient.SqlDataAdapter("select * from Event where convert(varchar, date_tb,103) = '" & currentDOBtext & "' and status <> 'D'", CNnWind) '& FormatDateTime(DateTimePicker1.Text, DateFormat.ShortDate) & "'", CNnWind) 'where date_tb = '" & datetimepickertext & "'", CNnWind)

        Dim selectedEventID As String
        selectedEventID = Trim(FrmPresentation.cboxMetasEvent.SelectedValue)
        Dim DAEvent As New SqlClient.SqlDataAdapter("select * from Event where Event_ID = '" & selectedEventID & "' and status <> 'D'", CNnWind)


        Dim currentPt_id As String
        'Load from event table
        Try
            DSNEvent = New DataSet()
            DSNEvent.Clear()
            CNnWind.Open()
            DAEvent.Fill(DSNEvent, "dtEvent")
            CNnWind.Close()

            'reset event counter if there are records
            If DSNEvent.Tables("dtEvent").Rows.Count >= 1 Then
                inc = 0
                lblCurrentRecord.Text = 1
                lbltotalrecord.Text = DSNEvent.Tables("dtEvent").Rows.Count
                btnSave.Enabled = True

            Else
                lbltotalrecord.Text = DSNEvent.Tables("dtEvent").Rows.Count
                lblCurrentRecord.Text = 0
                currentEventID = ""
                currentPt_id = ""
                ClearAllFields()
                DSNEvent.Tables("dtEvent").Clear()
                btnSave.Enabled = False
                lblEvent.Text = ""
                FrmMain.Button1.Text = ""
                Exit Sub
            End If


            'load from event table
            currentEventID = DSNEvent.Tables("dtEvent").Rows(inc).Item("Event_ID")
            currentPt_id = DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1")
            lblEvent.Text = currentEventID
            'GV_SELECTED_EVENTID = currentEventID
            DOB.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("date_tb")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("date_tb"))
            DateTimePicker1.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("date_cn")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("date_cn"))
            cbxDoctor.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("doc_inc")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("doc_inc"))
            CbxCaseType.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("case_type")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("case_type"))
            CbxLaterality.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("brst_screen")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("brst_screen"))
            cboxMeta.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasyn_Status")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasyn_Status"))
            GV_CUR_PATID = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1"))

            Lbl_EnBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("EnteredBy"))
            Lbl_UpdBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("UpdatedBy"))
            Lbl_LockBy.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedBy")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("LockedBy"))
            Lbl_EnBy.Visible = True
            Lbl_UpdBy.Visible = True
            Lbl_LockBy.Visible = True
        Catch a As Exception
            'turned off by cherwei, used for validation
            'MsgBox(a.ToString)
            Exit Sub
        End Try

        Dim currenteventstatus As String
        currenteventstatus = DSNEvent.Tables("dtEvent").Rows(inc).Item("Status")
        If currenteventstatus = "P" Then
            btnSave.Enabled = False
        Else
            btnSave.Enabled = True
        End If

        LoadMetasynchronous()
        cboxMetasEvent.SelectedValue = DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasynchronous")

        'Load from patient table, retrieve name and nric
        Dim DAPatient As New SqlClient.SqlDataAdapter("select distinct * from patients where Pt_id1 = '" & currentPt_id & "'", CNnWind)
        DSNPatient = New DataSet()
        CNnWind.Open()
        DAPatient.Fill(DSNPatient, "dtPatient")
        CNnWind.Close()

        count = DSNPatient.Tables("dtPatient").Rows.Count


        If (count > 0) Then
            PatName.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtName")
            PatNRIC.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtNRIC")
            lblAge.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtAge")
        End If

        'Load from investigation table
        Dim DAInvestigation As New SqlClient.SqlDataAdapter("select * from Investigation where event_id = '" & currentEventID & "' and status <> 'D'", CNnWind)
        DSNInvestigation = New DataSet()
        CNnWind.Open()
        DAInvestigation.Fill(DSNInvestigation, "dtInvestigation")
        CNnWind.Close()

        count = DSNInvestigation.Tables("dtInvestigation").Rows.Count
        If (count > 0) Then

            currentInvestigationID = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Inv_id")
            'GV_SELECTED_INVESTID = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Inv_id")
            cbxCXR.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CXR")
            cbxCT.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CT")
            cbxBone.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("BoneScan")
            RichTextNotes.Text = DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Notes")
            cbxCXR.Enabled = True
            cbxCT.Enabled = True
            cbxBone.Enabled = True
            RichTextNotes.Enabled = True
        Else
            cbxCXR.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CXR")
            cbxCT.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("CT")
            cbxBone.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("BoneScan")
            RichTextNotes.Text = "" 'DSNInvestigation.Tables("dtInvestigation").Rows(inc).Item("Notes")
            cbxCXR.Enabled = False
            cbxCT.Enabled = False
            cbxBone.Enabled = False
            RichTextNotes.Enabled = False

        End If
        'Load from history table
        Dim DAHistory As New SqlClient.SqlDataAdapter("select * from History where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNHistory = New DataSet()
        CNnWind.Open()
        DAHistory.Fill(DSNHistory, "dtHistory")
        CNnWind.Close()
        count = DSNHistory.Tables("dtHistory").Rows.Count
        If (count > 0) Then
            'GV_SELECTED_HISTORYID = DSNHistory.Tables("dtHistory").Rows(0).Item("History_ID")
            currentHistoryID = DSNHistory.Tables("dtHistory").Rows(0).Item("History_ID")
            cbxHistory.Text = DSNHistory.Tables("dtHistory").Rows(0).Item("FamilyHistory")
            cbxStatus.Text = DSNHistory.Tables("dtHistory").Rows(0).Item("Menstrual")
            cbxHistory.Enabled = True
            cbxStatus.Enabled = True
        Else
            cbxHistory.Text = "" 'DSNHistory.Tables("dtHistory").Rows(inc).Item("FamilyHistory")
            cbxStatus.Text = "" ' DSNHistory.Tables("dtHistory").Rows(inc).Item("Menstrual")

            cbxHistory.Enabled = False
            cbxStatus.Enabled = False
        End If

        'Load from histology table

        Dim DAHistology As New SqlClient.SqlDataAdapter("select * from Histology where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNHistology = New DataSet()
        CNnWind.Open()
        DAHistology.Fill(DSNHistology, "dtHistology")
        CNnWind.Close()

        count = DSNHistology.Tables("dtHistology").Rows.Count
        If (count > 0) Then
            'GV_SELECTED_HISTOLOGYID = DSNHistology.Tables("dtHistology").Rows(0).Item("histo_id")
            currentHistologyID = DSNHistology.Tables("dtHistology").Rows(0).Item("histo_id")
            lblHistology.Text = currentHistologyID
            txtTumourSize.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size"))
            cbxExtChestWall.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw"))
            cbxClinAxillaryLN.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln"))
            cbxTypeBiopsy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type"))
            dtDateBiopsy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy"))
            cbxHistoDx.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx"))
            DtPrisurg.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg"))
            cbxTypeSurg.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type"))
            cbxReconstruction.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction"))
            cboxNeoadjuvant.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj"))
            cboxLocalRec.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local"))
            cboxSystemic.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic"))
            txtPhysicalNotes.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes"))
            txtHistoNotes.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes"))
            txtHisto_TumourSize.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size"))
            cbxHistoType.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type"))
            cbxHistoGrade.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade"))
            cbxDCIS.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis"))
            cbxLymhovascular.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv"))
            cbxMargin_invasive.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca"))
            cboxMarginDCIS.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis"))
            cbxradialMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg"))
            txtRadialMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size"))
            txtDeepMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size"))
            cbxSentinel_LN.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1"))
            cbxSentinelLNPolarity.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_2")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_2"))
            txtTotal_Ax_LN_Postive.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos"))
            txtTotal_Ax_LN_Found.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))


            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("er_status"))
            cbxPR_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status"))
            cbxErbB2.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status"))
            cbxcT_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6"))
            cbxN_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6"))
            cbxM_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6"))


            txtTumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
            cbxExtChestWall.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
            cbxClinAxillaryLN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
            cbxTypeBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
            dtDateBiopsy.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
            cbxHistoDx.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
            DtPrisurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
            cbxTypeSurg.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
            cbxReconstruction.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
            cboxNeoadjuvant.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
            cboxLocalRec.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
            cboxSystemic.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
            txtPhysicalNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
            txtHistoNotes.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
            txtHisto_TumourSize.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
            cbxHistoType.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
            cbxHistoGrade.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
            cbxDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
            cbxLymhovascular.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
            cbxMargin_invasive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
            cboxMarginDCIS.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
            cbxradialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
            txtRadialMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
            txtDeepMargin.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
            cbxSentinel_LN.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
            txtTotal_Ax_LN_Postive.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
            cbxPR_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
            cbxErbB2.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
            cbxcT_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
            cbxN_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
            cbxM_Status.Enabled = True 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")
            cbxSentinelLNPolarity.Enabled = True

        Else
            txtTumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_tum_size")
            cbxExtChestWall.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("Ext_cw")
            cbxClinAxillaryLN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("clin_ax_ln")
            cbxTypeBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("biopsy_Type")
            dtDateBiopsy.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_biopsy")
            cbxHistoDx.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_Dx")
            DtPrisurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("date_pri_surg")
            cbxTypeSurg.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("surg_type")
            cbxReconstruction.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("reconstruction")
            cboxNeoadjuvant.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Neoadj")
            cboxLocalRec.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Local")
            cboxSystemic.Checked = False 'DSNHistology.Tables("dtHistology").Rows(inc).Item("chk_Systemic")
            txtPhysicalNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("add_physurg_notes")
            txtHistoNotes.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("other_histo_notes")
            txtHisto_TumourSize.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_tum_size")
            cbxHistoType.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_type")
            cbxHistoGrade.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("histo_grade")
            cbxDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ass_dcis")
            cbxLymhovascular.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("lymphovas_inv")
            cbxMargin_invasive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_inv_ca")
            cboxMarginDCIS.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("marg_dcis")
            cbxradialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg")
            txtRadialMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("closest_marg_size")
            txtDeepMargin.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("deep_marg_size")
            cbxSentinel_LN.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("SLN_1")
            txtTotal_Ax_LN_Postive.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))
            cbxER_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("er_status")
            cbxPR_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("pr_status")
            cbxErbB2.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("c_erbb2_status")
            cbxcT_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("t_stage_6")
            cbxN_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("n_stage_6")
            cbxM_Status.Text = "" 'DSNHistology.Tables("dtHistology").Rows(inc).Item("m_stage_6")

            txtTumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")
            cbxExtChestWall.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")
            cbxClinAxillaryLN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")
            cbxTypeBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")
            dtDateBiopsy.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")
            cbxHistoDx.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")
            DtPrisurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")
            cbxTypeSurg.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")
            cbxReconstruction.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")
            cboxNeoadjuvant.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")
            cboxLocalRec.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")
            cboxSystemic.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")
            txtPhysicalNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")
            txtHistoNotes.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")
            txtHisto_TumourSize.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")
            cbxHistoType.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")
            cbxHistoGrade.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")
            cbxDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")
            cbxLymhovascular.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")
            cbxMargin_invasive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")
            cboxMarginDCIS.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")
            cbxradialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")
            txtRadialMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")
            txtDeepMargin.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")
            cbxSentinel_LN.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")
            txtTotal_Ax_LN_Postive.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")
            txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd"))

            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")
            cbxPR_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")
            cbxErbB2.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")
            cbxcT_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")
            cbxN_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")
            cbxM_Status.Enabled = False 'DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")

            cbxSentinelLNPolarity.Enabled = False

        End If


        'Load from TxRecommendation
        Dim DATxRecommendation As New SqlClient.SqlDataAdapter("select * from recom where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNTxRecommendation = New DataSet()
        CNnWind.Open()
        DATxRecommendation.Fill(DSNTxRecommendation, "dtTxRecommendation")
        CNnWind.Close()

        count = DSNTxRecommendation.Tables("dtTxRecommendation").Rows.Count
        If (count > 0) Then
            'GV_SELECTED_TXID = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recom_id")
            currentTxID = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recom_id")
            cbxBTBRecommend.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommendation")
            cboxChemo.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Checked = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Text = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

            cbxBTBRecommend.Enabled = True
            cboxChemo.Enabled = True  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Enabled = True 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Enabled = True
        Else
            cbxBTBRecommend.Text = ""
            cboxChemo.Checked = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Checked = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Text = "" 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")

            cbxBTBRecommend.Enabled = False
            cboxChemo.Enabled = False  'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")
            cboxHormonal.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")
            cboxRadio.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")
            cboxSurgery.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")
            cboxTargerted.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")
            cboxComplete.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")
            txtComments.Enabled = False 'DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")
            txtNotes.Enabled = False
        End If

        maxrows = DSNEvent.Tables("dtEvent").Rows.Count
        inc = 0

        GV_CUR_PATNRIC = PatNRIC.Text
        GV_CUR_PATNAME = PatName.Text

        'Catch
        'MsgBox("No records found for selected BTB date: '" & DOB.Text & "'")
        'End Try


        'Added to allow auto popup when neoadj or priortx popup exists
        'If (cboxNeoadjuvant.Checked = True) Then
        'FrmNeoadjuvant.ShowDialog()
        'End If

        'If (cboxLocalRec.Checked = True) Then
        'FrmRcdPriorTreatment.ShowDialog()
        'End If

        'If (cboxNeoadjuvant.Checked = True And cboxLocalRec.Checked = True) Then
        'FrmNeoadjuvant.ShowDialog()
        'FrmRcdPriorTreatment.ShowDialog()
        'End If

        If (cboxNeoadjuvant.Checked = True And cboxLocalRec.Checked = True) Then
            FrmNeoadjuvantView.ShowDialog()
            FrmRcdPriorTreatmentView.ShowDialog()
        ElseIf (cboxNeoadjuvant.Checked = True) Then
            FrmNeoadjuvantView.ShowDialog()
        ElseIf (cboxLocalRec.Checked = True) Then
            FrmRcdPriorTreatmentView.ShowDialog()
        Else
        End If

    End Sub
    Private Sub LoadFamilyHistory()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 2", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxHistory.DataSource = list
            Me.cbxHistory.DisplayMember = "code_desc"
            Me.cbxHistory.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub NavigateRecords()
        'Event form for input
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        'Load from event table
        Dim currentEventID As String
        currentEventID = DSNEvent.Tables("dtEvent").Rows(inc).Item("Event_ID")
        lblEvent.Text = currentEventID
        GV_SELECTED_EVENTID = currentEventID
        DOB.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("date_tb")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("date_tb"))
        DateTimePicker1.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("date_cn")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("date_cn"))
        cbxDoctor.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("doc_inc")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("doc_inc"))
        CbxCaseType.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("case_type")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("case_type"))
        CbxLaterality.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("brst_screen")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("brst_screen"))
        cboxMeta.Text = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasyn_Status")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasyn_Status"))
        GV_CUR_PATID = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Pt_id1"))
        GV_SELECTED_EVENTID = currentEventID
        LoadMetasynchronous()
        cboxMetasEvent.SelectedValue = IIf(IsDBNull(DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasynchronous")), "", DSNEvent.Tables("dtEvent").Rows(inc).Item("Metasynchronous"))

        'Load from NeoAdj table to retrieve current neoadj_id
        Dim vNeoAdj_ID As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select Neoadj_id from NEOADJ where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
        Try
            Dim DANeoAdj As New SqlClient.SqlDataAdapter("select Neoadj_id from NEOADJ where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection1)
            Dim DSNNeoAdj = New DataSet()
            CNnWind.Open()
            DANeoAdj.Fill(DSNNeoAdj, "dtTempNeoAdj")
            CNnWind.Close()

            If (DSNNeoAdj.Tables("dtTempNeoAdj").Rows.Count > 0) Then
                GV_SELECTED_NEOADJID = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Neoadj_id")
                vNeoAdj_ID = GV_SELECTED_NEOADJID
            Else
                GV_SELECTED_NEOADJID = ""
                vNeoAdj_ID = ""
            End If


            'Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            'If Not (objReader Is Nothing) Then
            'Do While objReader.Read
            'vNeoAdj_ID = IIf(IsDBNull(objReader("Neoadj_id")), "", objReader("Neoadj_id"))
            'GV_SELECTED_NEOADJID = vNeoAdj_ID
            'Loop
            'Else
            'GV_SELECTED_NEOADJID = ""
            'vNeoAdj_ID = ""
            'End If


        Catch ex As Exception
            MsgBox(ex.Source)
        End Try


        'Get current status from event table to allow or disallow save button
        Dim currenteventstatus As String
        currenteventstatus = DSNEvent.Tables("dtEvent").Rows(inc).Item("Status")
        If currenteventstatus = "P" Then
            btnSave.Enabled = False
        Else
            btnSave.Enabled = True
        End If

        'Load from patient table, retrieve name and nric
        Dim DAPatient As New SqlClient.SqlDataAdapter("select distinct * from patients where Pt_id1 = '" & GV_CUR_PATID & "'", CNnWind)
        DSNPatient = New DataSet()
        CNnWind.Open()
        DAPatient.Fill(DSNPatient, "dtPatient")
        CNnWind.Close()

        If (DSNPatient.Tables("dtPatient").Rows.Count > 0) Then
            PatName.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtName")
            PatNRIC.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtNRIC")
            lblAge.Text = DSNPatient.Tables("dtPatient").Rows(0).Item("PtAge")
        End If

        'Load from investigation table
        Dim DAInvestigation As New SqlClient.SqlDataAdapter("select * from Investigation where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNInvestigation = New DataSet()
        CNnWind.Open()
        DAInvestigation.Fill(DSNInvestigation, "dtInvestigation")
        CNnWind.Close()
        Dim count As Integer
        count = DSNInvestigation.Tables("dtInvestigation").Rows.Count

        If (count > 0) Then

            GV_SELECTED_INVESTID = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Inv_ID")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Inv_ID"))
            cbxCXR.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CXR")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CXR"))
            cbxCT.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CT")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("CT"))
            cbxBone.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("BoneScan")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("BoneScan"))
            RichTextNotes.Text = IIf(IsDBNull(DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Notes")), "", DSNInvestigation.Tables("dtInvestigation").Rows(0).Item("Notes"))
            cbxCXR.Enabled = True
            cbxCT.Enabled = True
            cbxBone.Enabled = True
            RichTextNotes.Enabled = True
        Else
            cbxCXR.Text = ""
            cbxCT.Text = ""
            cbxBone.Text = ""
            RichTextNotes.Text = ""
            cbxCXR.Enabled = False
            cbxCT.Enabled = False
            cbxBone.Enabled = False
            RichTextNotes.Enabled = False
        End If

        'Load from history table
        Dim DAHistory As New SqlClient.SqlDataAdapter("select * from History where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNHistory = New DataSet()
        CNnWind.Open()
        DAHistory.Fill(DSNHistory, "dtHistory")
        CNnWind.Close()

        count = DSNHistory.Tables("dtHistory").Rows.Count
        If (count > 0) Then
            GV_SELECTED_HISTORYID = DSNHistory.Tables("dtHistory").Rows(0).Item("history_id")
            cbxHistory.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("FamilyHistory")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("FamilyHistory"))
            cbxStatus.Text = IIf(IsDBNull(DSNHistory.Tables("dtHistory").Rows(0).Item("Menstrual")), "", DSNHistory.Tables("dtHistory").Rows(0).Item("Menstrual"))
            cbxHistory.Enabled = True
            cbxStatus.Enabled = True
        Else
            cbxHistory.Text = ""
            cbxStatus.Text = ""
            cbxHistory.Enabled = False
            cbxStatus.Enabled = False
        End If

        'Load from histology table
        Dim DAHistology As New SqlClient.SqlDataAdapter("select * from Histology where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNHistology = New DataSet()
        CNnWind.Open()
        DAHistology.Fill(DSNHistology, "dtHistology")
        CNnWind.Close()

        count = DSNHistology.Tables("dtHistology").Rows.Count
        If (count > 0) Then

            GV_SELECTED_HISTOLOGYID = DSNHistology.Tables("dtHistology").Rows(0).Item("histo_id")
            txtTumourSize.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("clin_tum_size"))
            cbxExtChestWall.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("Ext_cw"))
            cbxClinAxillaryLN.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("clin_ax_ln"))
            cbxTypeBiopsy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type"))
            dtDateBiopsy.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy"))
            cbxHistoDx.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx"))
            DtPrisurg.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg"))
            cbxTypeSurg.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type"))
            cbxReconstruction.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction"))
            cboxNeoadjuvant.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj"))
            cboxLocalRec.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local"))
            cboxSystemic.Checked = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic"))
            txtPhysicalNotes.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes"))
            txtHistoNotes.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes"))
            txtHisto_TumourSize.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size"))
            cbxHistoType.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type"))
            cbxHistoGrade.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade"))
            cbxDCIS.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis"))
            cbxLymhovascular.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv"))
            cbxMargin_invasive.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca"))
            cboxMarginDCIS.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis"))
            cbxradialMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg"))
            txtRadialMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size"))
            txtDeepMargin.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size"))
            cbxSentinel_LN.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1"))
            txtTotal_Ax_LN_Postive.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos"))
            txtTotal_Ax_LN_Found.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd"))


            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("er_status"))
            cbxPR_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status"))
            cbxErbB2.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status"))
            cbxcT_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6"))
            cbxN_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("n_stage_6"))
            cbxM_Status.Text = IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("m_stage_6"))

            txtTumourSize.Enabled = True
            cbxExtChestWall.Enabled = True
            cbxClinAxillaryLN.Enabled = True
            cbxTypeBiopsy.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type"))
            dtDateBiopsy.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy"))
            cbxHistoDx.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx"))
            DtPrisurg.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg"))
            cbxTypeSurg.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type"))
            cbxReconstruction.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction"))
            cboxNeoadjuvant.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj"))
            cboxLocalRec.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local"))
            cboxSystemic.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic"))
            txtPhysicalNotes.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes"))
            txtHistoNotes.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes"))
            txtHisto_TumourSize.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size"))
            cbxHistoType.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type"))
            cbxHistoGrade.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade"))
            cbxDCIS.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis"))
            cbxLymhovascular.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv"))
            cbxMargin_invasive.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca"))
            cboxMarginDCIS.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis"))
            cbxradialMargin.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg"))
            txtRadialMargin.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size"))
            txtDeepMargin.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size"))
            cbxSentinel_LN.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1"))
            txtTotal_Ax_LN_Postive.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos"))
            txtTotal_Ax_LN_Found.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd"))
            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("er_status"))
            cbxPR_Status.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status"))
            cbxErbB2.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status"))
            cbxcT_Status.Enabled = True 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6"))
            cbxN_Status.Enabled = True
            cbxM_Status.Enabled = True


        Else
            GV_SELECTED_HISTOLOGYID = ""
            txtTumourSize.Text = ""
            cbxExtChestWall.Text = ""
            cbxClinAxillaryLN.Text = ""
            cbxTypeBiopsy.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type"))
            dtDateBiopsy.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy"))
            cbxHistoDx.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx"))
            DtPrisurg.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg"))
            cbxTypeSurg.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type"))
            cbxReconstruction.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction"))
            cboxNeoadjuvant.Checked = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj"))
            cboxLocalRec.Checked = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local"))
            cboxSystemic.Checked = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic"))
            txtPhysicalNotes.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes"))
            txtHistoNotes.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes"))
            txtHisto_TumourSize.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size"))
            cbxHistoType.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type"))
            cbxHistoGrade.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade"))
            cbxDCIS.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis"))
            cbxLymhovascular.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv"))
            cbxMargin_invasive.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca"))
            cboxMarginDCIS.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis"))
            cbxradialMargin.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg"))
            txtRadialMargin.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size"))
            txtDeepMargin.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size"))
            cbxSentinel_LN.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1"))
            txtTotal_Ax_LN_Postive.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos"))
            txtTotal_Ax_LN_Found.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd"))
            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("er_status"))
            cbxPR_Status.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status"))
            cbxErbB2.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status"))
            cbxcT_Status.Text = "" 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6"))
            cbxN_Status.Text = ""
            cbxM_Status.Text = ""


            txtTumourSize.Enabled = False
            cbxExtChestWall.Enabled = False
            cbxClinAxillaryLN.Enabled = False
            cbxTypeBiopsy.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("biopsy_Type"))
            dtDateBiopsy.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_biopsy"))
            cbxHistoDx.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_Dx"))
            DtPrisurg.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("date_pri_surg"))
            cbxTypeSurg.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("surg_type"))
            cbxReconstruction.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("reconstruction"))
            cboxNeoadjuvant.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Neoadj"))
            cboxLocalRec.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Local"))
            cboxSystemic.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("chk_Systemic"))
            txtPhysicalNotes.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("add_physurg_notes"))
            txtHistoNotes.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("other_histo_notes"))
            txtHisto_TumourSize.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_tum_size"))
            cbxHistoType.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_type"))
            cbxHistoGrade.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("histo_grade"))
            cbxDCIS.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ass_dcis"))
            cbxLymhovascular.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("lymphovas_inv"))
            cbxMargin_invasive.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_inv_ca"))
            cboxMarginDCIS.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("marg_dcis"))
            cbxradialMargin.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg"))
            txtRadialMargin.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("closest_marg_size"))
            txtDeepMargin.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("deep_marg_size"))
            cbxSentinel_LN.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("SLN_1"))
            txtTotal_Ax_LN_Postive.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_pos"))
            txtTotal_Ax_LN_Found.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("ax_ln_fd"))
            'txtTotal_Ax_LN_Found.Text = DSNHistology.Tables("dtHistology").Rows(inc).Item("ax_ln_fd")
            cbxER_Status.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("er_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("er_status"))
            cbxPR_Status.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("pr_status"))
            cbxErbB2.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("c_erbb2_status"))
            cbxcT_Status.Enabled = False 'IIf(IsDBNull(DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6")), "", DSNHistology.Tables("dtHistology").Rows(0).Item("t_stage_6"))
            cbxN_Status.Enabled = False
            cbxM_Status.Enabled = False

        End If

        'Load from TxRecommendation
        Dim DATxRecommendation As New SqlClient.SqlDataAdapter("select * from recom where event_id = '" & currentEventID & "'  and status <> 'D'", CNnWind)
        DSNTxRecommendation = New DataSet()
        CNnWind.Open()
        DATxRecommendation.Fill(DSNTxRecommendation, "dtTxRecommendation")
        CNnWind.Close()
        count = DSNTxRecommendation.Tables("dtTxRecommendation").Rows.Count
        If (count > 0) Then

            GV_SELECTED_TXID = DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recom_id")
            cbxBTBRecommend.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommendation")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommendation"))
            cboxChemo.Checked = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("chemotherapy"))
            cboxHormonal.Checked = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("hormonaltherapy"))
            cboxRadio.Checked = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("radiotherapy"))
            cboxSurgery.Checked = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("surgery"))
            cboxTargerted.Checked = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("immunotherapy"))
            cboxComplete.Checked = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("form_complete"))
            txtComments.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("recommend_notes"))
            txtNotes.Text = IIf(IsDBNull(DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes")), "", DSNTxRecommendation.Tables("dtTxRecommendation").Rows(0).Item("update_notes"))
            cbxBTBRecommend.Enabled = True
            cboxChemo.Enabled = True
            cboxHormonal.Enabled = True
            cboxRadio.Enabled = True
            cboxSurgery.Enabled = True
            cboxTargerted.Enabled = True
            cboxComplete.Enabled = True
            txtComments.Enabled = True
            txtNotes.Enabled = True
        Else
            cbxBTBRecommend.Text = ""
            cboxChemo.Checked = False
            cboxHormonal.Checked = False
            cboxRadio.Checked = False
            cboxSurgery.Checked = False
            cboxTargerted.Checked = False
            cboxComplete.Checked = False
            txtComments.Text = ""
            txtNotes.Text = ""

            cbxBTBRecommend.Enabled = False
            cboxChemo.Enabled = False
            cboxHormonal.Enabled = False
            cboxRadio.Enabled = False
            cboxSurgery.Enabled = False
            cboxTargerted.Enabled = False
            cboxComplete.Enabled = False
            txtComments.Enabled = False
            txtNotes.Enabled = False
        End If

        GV_CUR_PATNRIC = PatNRIC.Text
        GV_CUR_PATNAME = PatName.Text


        'modified to auto popup neoadjuvant and priorttx treatment if exists
        'If (cboxNeoadjuvant.Checked = True) Then
        'FrmNeoadjuvant.ShowDialog()
        'End If

        'If (cboxLocalRec.Checked = True) Then
        'FrmRcdPriorTreatment.ShowDialog()
        'End If

        If (cboxNeoadjuvant.Checked = True And cboxLocalRec.Checked = True) Then
            FrmNeoadjuvantView.ShowDialog()
            FrmRcdPriorTreatmentView.ShowDialog()
        ElseIf (cboxNeoadjuvant.Checked = True) Then
            FrmNeoadjuvantView.ShowDialog()
        ElseIf (cboxLocalRec.Checked = True) Then
            FrmRcdPriorTreatmentView.ShowDialog()
        Else
        End If

    End Sub

    Private Sub BindingNavigatorMovePreviousItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        Me.BindingContext(DSNEvent, "Text").Position += 1

    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Dim message As String
        Try
            If (PatNRIC.Text = "NRIC" Or DSNEvent.Tables("dtEvent").Rows.Count = 0) Then
                'If (DSNEvent.Tables("dtEvent").Rows.Count = 0) Then
                Exit Sub
            End If
            If inc <> (maxrows - 1) Then
                inc = inc + 1
                lblCurrentRecord.Text = lblCurrentRecord.Text + 1
                NavigateRecords()
            Else
                MsgBox("Last Record")
            End If

        Catch ex As Exception

            message = ""
            message = ex.ToString()
            MsgBox(ex.ToString())
        End Try
    End Sub

    Private Sub LoadDoctor()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value  83", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.cbxDoctor.DataSource = list
            Me.cbxDoctor.DisplayMember = "code_desc"
            Me.cbxDoctor.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadCaseType()

        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 84", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.CbxCaseType.DataSource = list
            Me.CbxCaseType.DisplayMember = "code_desc"
            Me.CbxCaseType.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadLaterality()


        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("exec spGetlookup_Value 9", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("code_desc", GetType(String)))
            list.Columns.Add(New DataColumn("code", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("code_desc")), "", objReader("code_desc"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("code")), "", objReader("code"))
                i = i + 1
            Loop
            Me.CbxLaterality.DataSource = list
            Me.CbxLaterality.DisplayMember = "code_desc"
            Me.CbxLaterality.ValueMember = "code"

        Catch e As Exception
            MsgBox(e.Source)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub LoadMetasynchronous()
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("spGetMetasyn", SqlConnection1)
        sqlCmd.Parameters.Add("@Pt_ID1", SqlDbType.Int)
        sqlCmd.Parameters.Add("@Event_Id", SqlDbType.Char)
        sqlCmd.Parameters("@Pt_ID1").Value = GV_CUR_PATID
        sqlCmd.Parameters("@Event_Id").Value = GV_SELECTED_EVENTID
        sqlCmd.CommandType = CommandType.StoredProcedure
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Dim i As Integer
            i = 1
            Dim list As New DataTable
            list.Columns.Add(New DataColumn("brst_screen", GetType(String)))
            list.Columns.Add(New DataColumn("Event_ID", GetType(String)))
            list.Rows.Add(list.NewRow())
            list.Rows(0)(0) = ""
            list.Rows(0)(1) = ""
            Do While objReader.Read
                list.Rows.Add(list.NewRow())
                list.Rows(i)(0) = IIf(IsDBNull(objReader("brst_screen")), "", objReader("brst_screen"))
                list.Rows(i)(1) = IIf(IsDBNull(objReader("Event_ID")), "", objReader("Event_ID"))
                i = i + 1
            Loop
            Me.cboxMetasEvent.DataSource = list
            Me.cboxMetasEvent.DisplayMember = "brst_screen"
            Me.cboxMetasEvent.ValueMember = "Event_ID"

        Catch e As Exception
            MsgBox(e.Source & e.Message)
        End Try

        sqlCmd.Cancel()
        SqlConnection1.Close()
        sqlCmd = Nothing
        SqlConnection1.Close()
    End Sub

    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
        Try

            If (PatNRIC.Text = "NRIC" Or DSNEvent.Tables("dtEvent").Rows.Count = 0) Then
                Exit Sub
            End If
            'If (DSNEvent.Tables("dtEvent").Rows.Count = 0) Then
            '   Exit Sub
            'End If
            If inc > 0 Then
                inc = inc - 1
                lblCurrentRecord.Text = lblCurrentRecord.Text - 1
                NavigateRecords()
            ElseIf inc = -1 Then
                MsgBox("No records yet")
            ElseIf inc = 0 Then
                MsgBox("First Record")
            End If
        Catch t As Exception

        End Try


    End Sub

    Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
        'Once copy button is clicked, get the current selected btb date from DOB control and insert new rows into event and respective tables
        'check if event is locked, enable/disable save button
        If Trim(GV_SELECTED_EVENTID) = "" Then
            btnSave.Enabled = False
            btnCopy.Enabled = False
            Exit Sub
        Else
            btnSave.Enabled = True
            btnCopy.Enabled = True
        End If



        'Perform the save functions
        'save function for event
        Dim myCommand As SqlCommand
        Dim SqlConn As New SqlConnection()
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertEvent", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@date_tb", SqlDbType.DateTime)
        myCommand.Parameters.Add("@date_cn", SqlDbType.DateTime)
        myCommand.Parameters.Add("@doc_inc", SqlDbType.VarChar)
        myCommand.Parameters.Add("@case_type", SqlDbType.VarChar)
        myCommand.Parameters.Add("@brst_screen", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasyn_Status", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Metasynchronous", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID_old", SqlDbType.VarChar)


        'check again, if patient data is in database, do not execute
        Dim vNewEventID As String = ""
        Dim SqlConnection2 As New SqlConnection()
        SqlConnection2 = New SqlConnection(GV_CONNETION)
        If SqlConnection2.State = ConnectionState.Closed Then SqlConnection2.Open()
        Dim sqlCmd2 = New SqlCommand("SELECT COUNT(EVENT_ID) + 1 as new_event_id FROM EVENT", SqlConnection2)
        Try
            Dim objReader As SqlDataReader = sqlCmd2.ExecuteReader
            Do While objReader.Read
                vNewEventID = IIf(IsDBNull(objReader("new_event_id")), "", objReader("new_event_id"))
            Loop

        Catch ex As Exception
            MsgBox(ex.Source)
            Exit Sub
        End Try

        SqlConnection2.Close()

        vNewEventID = "E" + vNewEventID

        'check n retrieve current eventid on the form, if eventid is empty, gv_isedit = false else gv_isedit = true
        'If Trim(lblEvent.Text).IndexOf("E") = -1 Then
        'GV_ISEDIT = False
        'Else
        'GV_ISEDIT = True
        'End If

        'If GV_ISEDIT = True Then
        'myCommand.Parameters("@Event_ID").Value = GV_SELECTED_EVENTID
        'Else
        myCommand.Parameters("@Event_ID").Value = "0"
        myCommand.Parameters("@Event_ID_old").Value = GV_SELECTED_EVENTID
        'End If
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@date_tb").Value = FormatDateTime(DOB.Value, DateFormat.ShortDate)
        myCommand.Parameters("@date_cn").Value = FormatDateTime(DateTimePicker1.Value, DateFormat.ShortDate)
        myCommand.Parameters("@doc_inc").Value = Trim(cbxDoctor.Text)
        myCommand.Parameters("@case_type").Value = Trim(CbxCaseType.Text)
        myCommand.Parameters("@brst_screen").Value = Trim(CbxLaterality.Text)
        myCommand.Parameters("@Metasyn_Status").Value = Trim(cboxMeta.Text)
        myCommand.Parameters("@Metasynchronous").Value = Trim(cboxMetasEvent.SelectedValue)
        myCommand.Parameters("@EnteredBy").Value = GV_USER

        'check again, if patient data is in database, do not execute
        Dim vPatID As String = ""
        Dim SqlConnection1 As New SqlConnection()
        SqlConnection1 = New SqlConnection(GV_CONNETION)
        If SqlConnection1.State = ConnectionState.Closed Then SqlConnection1.Open()
        Dim sqlCmd = New SqlCommand("select ptNRIC from PATIENTS where ptNRIC = '" & PatNRIC.Text & "'", SqlConnection1)
        Try
            Dim objReader As SqlDataReader = sqlCmd.ExecuteReader
            Do While objReader.Read
                vPatID = IIf(IsDBNull(objReader("ptNRIC")), "", objReader("ptNRIC"))
            Loop

        Catch ex As Exception
            MsgBox(ex.Source)
            Exit Sub
        End Try


        'If LTrim(RTrim(vPatID)) = "" Then
        'MsgBox("Please load an existing event first")
        'btnSave.Enabled = False
        'sqlCmd.Cancel()
        'SqlConnection1.Close()
        'sqlCmd = Nothing
        'SqlConnection1.Close()
        'Else
        myCommand.ExecuteNonQuery()

        'perform the save procedures to other tables 
        'save function for investigation
        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertInvestigation", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@Inv_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@CXR", SqlDbType.VarChar)
        myCommand.Parameters.Add("@CT", SqlDbType.VarChar)
        myCommand.Parameters.Add("@BoneScan", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        'If Trim(GV_SELECTED_INVESTID).IndexOf("I") = -1 Then
        'GV_ISEDIT = False
        'Else
        'GV_ISEDIT = True
        'End If

        'If GV_ISEDIT = True Then
        'myCommand.Parameters("@Inv_ID").Value = GV_SELECTED_INVESTID
        'Else
        myCommand.Parameters("@Inv_ID").Value = "0"
        'End If
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@Event_ID").Value = vNewEventID 'GV_SELECTED_EVENTID
        myCommand.Parameters("@CXR").Value = Trim(cbxCXR.SelectedValue)
        myCommand.Parameters("@CT").Value = Trim(cbxCT.SelectedValue)
        myCommand.Parameters("@BoneScan").Value = Trim(cbxBone.SelectedValue)
        myCommand.Parameters("@Notes").Value = Trim(RichTextNotes.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER

        If Trim(GV_SELECTED_INVESTID).IndexOf("I") = -1 Then

        Else
            myCommand.ExecuteNonQuery()

        End If

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing


        'save function for tx recommendation details

        SqlConn = New SqlConnection(GV_CONNETION)
        myCommand = New SqlCommand("spInsertTxRecommendation", SqlConn)
        myCommand.CommandType = CommandType.StoredProcedure
        SqlConn.Open()

        myCommand.Parameters.Add("@recom_id", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
        myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
        myCommand.Parameters.Add("@recommendation", SqlDbType.VarChar)
        myCommand.Parameters.Add("@chemotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@hormonaltherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@radiotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@surgery", SqlDbType.Bit)
        myCommand.Parameters.Add("@immunotherapy", SqlDbType.Bit)
        myCommand.Parameters.Add("@recommend_notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@form_complete", SqlDbType.Bit)
        myCommand.Parameters.Add("@update_notes", SqlDbType.VarChar)
        myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

        'If Trim(GV_SELECTED_TXID).IndexOf("T") = -1 Then
        'GV_ISEDIT = False
        'Else
        'GV_ISEDIT = True
        'End If

        'If GV_ISEDIT = True Then
        'myCommand.Parameters("@recom_id").Value = GV_SELECTED_TXID
        'Else
        myCommand.Parameters("@recom_id").Value = "0"

        'End If
        myCommand.Parameters("@Event_ID").Value = vNewEventID 'GV_SELECTED_EVENTID
        myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
        myCommand.Parameters("@recommendation").Value = Trim(cbxBTBRecommend.Text)
        myCommand.Parameters("@chemotherapy").Value = cboxChemo.Checked
        myCommand.Parameters("@hormonaltherapy").Value = cboxHormonal.Checked
        myCommand.Parameters("@radiotherapy").Value = cboxRadio.Checked
        myCommand.Parameters("@surgery").Value = cboxSurgery.Checked
        myCommand.Parameters("@immunotherapy").Value = cboxTargerted.Checked
        myCommand.Parameters("@recommend_notes").Value = Trim(txtComments.Text)
        myCommand.Parameters("@form_complete").Value = cboxComplete.Checked
        myCommand.Parameters("@update_notes").Value = Trim(txtNotes.Text)
        myCommand.Parameters("@EnteredBy").Value = GV_USER
        If Trim(GV_SELECTED_TXID).IndexOf("T") = -1 Then

        Else
            myCommand.ExecuteNonQuery()
        End If

        myCommand.Cancel()
        SqlConn.Close()
        myCommand = Nothing
        SqlConn = Nothing


        'save histology table
        Try
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertHistology", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Ext_cw", SqlDbType.VarChar)
            myCommand.Parameters.Add("@clin_ax_ln", SqlDbType.VarChar)
            myCommand.Parameters.Add("@biopsy_Type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_biopsy", SqlDbType.DateTime)
            myCommand.Parameters.Add("@histo_Dx", SqlDbType.VarChar)
            myCommand.Parameters.Add("@date_pri_surg", SqlDbType.DateTime)
            myCommand.Parameters.Add("@surg_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@reconstruction", SqlDbType.VarChar)
            myCommand.Parameters.Add("@chk_Neoadj", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Local", SqlDbType.Bit)
            myCommand.Parameters.Add("@chk_Systemic", SqlDbType.Bit)
            myCommand.Parameters.Add("@add_physurg_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@other_histo_notes", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_tum_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_type", SqlDbType.VarChar)
            myCommand.Parameters.Add("@histo_grade", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ass_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@lymphovas_inv", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_inv_ca", SqlDbType.VarChar)
            myCommand.Parameters.Add("@marg_dcis", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg", SqlDbType.VarChar)
            myCommand.Parameters.Add("@closest_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@deep_marg_size", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@SLN_2", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_pos", SqlDbType.VarChar)
            myCommand.Parameters.Add("@ax_ln_fd", SqlDbType.VarChar)
            myCommand.Parameters.Add("@er_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@pr_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@c_erbb2_status", SqlDbType.VarChar)
            myCommand.Parameters.Add("@t_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@n_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@m_stage_6", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            'If Trim(GV_SELECTED_HISTOLOGYID).IndexOf("S") = -1 Then
            'GV_ISEDIT = False
            'Else
            'GV_ISEDIT = True
            'End If

            'If GV_ISEDIT = True Then
            'myCommand.Parameters("@Histo_ID").Value = GV_SELECTED_HISTOLOGYID
            'Else
            myCommand.Parameters("@Histo_ID").Value = "0"
            'End If
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = vNewEventID 'GV_SELECTED_EVENTID
            myCommand.Parameters("@clin_tum_size").Value = Trim(txtTumourSize.Text)
            myCommand.Parameters("@Ext_cw").Value = Trim(cbxExtChestWall.Text)
            myCommand.Parameters("@clin_ax_ln").Value = Trim(cbxClinAxillaryLN.Text)
            myCommand.Parameters("@biopsy_Type").Value = Trim(cbxTypeBiopsy.Text)
            myCommand.Parameters("@date_biopsy").Value = dtDateBiopsy.Value
            myCommand.Parameters("@histo_Dx").Value = Trim(cbxHistoDx.Text)
            myCommand.Parameters("@date_pri_surg").Value = DtPrisurg.Value
            myCommand.Parameters("@surg_type").Value = Trim(cbxTypeSurg.Text)
            myCommand.Parameters("@reconstruction").Value = Trim(cbxReconstruction.Text)
            myCommand.Parameters("@chk_Neoadj").Value = cboxNeoadjuvant.Checked
            myCommand.Parameters("@chk_Local").Value = cboxLocalRec.Checked
            myCommand.Parameters("@chk_Systemic").Value = cboxSystemic.Checked
            myCommand.Parameters("@add_physurg_notes").Value = Trim(txtPhysicalNotes.Text)
            myCommand.Parameters("@other_histo_notes").Value = Trim(txtHistoNotes.Text)
            myCommand.Parameters("@histo_tum_size").Value = Trim(txtHisto_TumourSize.Text)
            myCommand.Parameters("@histo_type").Value = Trim(cbxHistoType.Text)
            myCommand.Parameters("@histo_grade").Value = Trim(cbxHistoGrade.Text)
            myCommand.Parameters("@ass_dcis").Value = Trim(cbxDCIS.Text)
            myCommand.Parameters("@lymphovas_inv").Value = Trim(cbxLymhovascular.Text)
            myCommand.Parameters("@marg_inv_ca").Value = Trim(cbxMargin_invasive.Text)
            myCommand.Parameters("@marg_dcis").Value = Trim(cboxMarginDCIS.Text)
            myCommand.Parameters("@closest_marg").Value = Trim(cbxradialMargin.Text)
            myCommand.Parameters("@closest_marg_size").Value = Trim(txtRadialMargin.Text)
            myCommand.Parameters("@deep_marg_size").Value = Trim(txtDeepMargin.Text)
            myCommand.Parameters("@SLN_1").Value = Trim(cbxSentinel_LN.Text)
            myCommand.Parameters("@SLN_2").Value = Trim(cbxSentinelLNPolarity.Text)
            myCommand.Parameters("@ax_ln_pos").Value = Trim(txtTotal_Ax_LN_Postive.Text)
            myCommand.Parameters("@ax_ln_fd").Value = Trim(txtTotal_Ax_LN_Found.Text)
            myCommand.Parameters("@er_status").Value = Trim(cbxER_Status.Text)
            myCommand.Parameters("@pr_status").Value = Trim(cbxPR_Status.Text)
            myCommand.Parameters("@c_erbb2_status").Value = Trim(cbxErbB2.Text)
            myCommand.Parameters("@t_stage_6").Value = Trim(cbxcT_Status.Text)
            myCommand.Parameters("@n_stage_6").Value = Trim(cbxN_Status.Text)
            myCommand.Parameters("@m_stage_6").Value = Trim(cbxM_Status.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER
            If Trim(GV_SELECTED_HISTOLOGYID).IndexOf("S") = -1 Then

            Else
                myCommand.ExecuteNonQuery()


            End If

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try

        'save history table
        Try
            SqlConn = New SqlConnection(GV_CONNETION)
            myCommand = New SqlCommand("spInsertHistory", SqlConn)
            myCommand.CommandType = CommandType.StoredProcedure
            SqlConn.Open()

            myCommand.Parameters.Add("@History_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
            myCommand.Parameters.Add("@FamilyHistory", SqlDbType.VarChar)
            myCommand.Parameters.Add("@Menstrual", SqlDbType.VarChar)
            myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

            If Trim(GV_SELECTED_HISTORYID).IndexOf("H") = -1 Then
                GV_ISEDIT = False
            Else
                GV_ISEDIT = True
            End If

            'If GV_ISEDIT = True Then
            'myCommand.Parameters("@History_ID").Value = GV_SELECTED_HISTORYID
            'Else
            myCommand.Parameters("@History_ID").Value = "0"
            'End If
            myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
            myCommand.Parameters("@Event_ID").Value = vNewEventID 'GV_SELECTED_EVENTID
            myCommand.Parameters("@FamilyHistory").Value = Trim(cbxHistory.Text)
            myCommand.Parameters("@Menstrual").Value = Trim(cbxStatus.Text)
            myCommand.Parameters("@EnteredBy").Value = GV_USER

            If Trim(GV_SELECTED_HISTORYID).IndexOf("H") = -1 Then

            Else
                myCommand.ExecuteNonQuery()
            End If

            myCommand.Cancel()
            SqlConn.Close()
            myCommand = Nothing
            SqlConn = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try

  


        'Load from NeoAdj table to retrieve current neoadj_id
        Dim vNeoAdj_ID As String = ""
        Dim vEvent_ID As String = ""
        Dim vPt_id1 As String = ""
        Dim vHisto_ID As String = ""
        Dim vt_stage_6 As String = ""
        Dim vn_stage_6 As String = ""
        Dim vm_stage_6 As String = ""
        Dim vNeoadj_tum_size As String = ""
        Dim vDate_biopsy_done As DateTime
        Dim vType_Biopsy As String = ""
        Dim vNeoadj_Details As String = ""
        Dim vPostChemo_tum_size As String = ""
        Dim vPostChemo_Ax_LN As String = ""
        Dim vResponse_chemo As String = ""
        Dim vEnteredBy As DateTime
        Dim SqlConnection3 As New SqlConnection()
        Dim CNnWind As New SqlClient.SqlConnection(GV_CONNETION)
        SqlConnection3 = New SqlConnection(GV_CONNETION)
        If SqlConnection3.State = ConnectionState.Closed Then SqlConnection3.Open()
        Dim sqlCmd3 = New SqlCommand("select Neoadj_ID,Event_ID,Pt_id1,Histo_ID,t_stage_6,n_stage_6,m_stage_6,Neoadj_tum_size,Date_biopsy_done,Type_Biopsy,Neoadj_Details,PostChemo_tum_size,PostChemo_Ax_LN,Response_chemo,EnteredBy from NEOADJ where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection3)
        Try
            Dim DANeoAdj As New SqlClient.SqlDataAdapter("select Neoadj_ID,Event_ID,Pt_id1,Histo_ID,t_stage_6,n_stage_6,m_stage_6,Neoadj_tum_size,Date_biopsy_done,Type_Biopsy,Neoadj_Details,PostChemo_tum_size,PostChemo_Ax_LN,Response_chemo,EnteredBy from NEOADJ where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection3)
            Dim DSNNeoAdj = New DataSet()
            CNnWind.Open()
            DANeoAdj.Fill(DSNNeoAdj, "dtTempNeoAdj")
            CNnWind.Close()




            If (DSNNeoAdj.Tables("dtTempNeoAdj").Rows.Count > 0) Then
                GV_SELECTED_NEOADJID = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Neoadj_id")
                vNeoAdj_ID = GV_SELECTED_NEOADJID
                vNeoAdj_ID = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Neoadj_ID")
                vEvent_ID = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Event_ID")
                vPt_id1 = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Pt_id1")
                vHisto_ID = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Histo_ID")
                vt_stage_6 = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("t_stage_6")
                vn_stage_6 = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("n_stage_6")
                vm_stage_6 = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("m_stage_6")
                vNeoadj_tum_size = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Neoadj_tum_size")
                vDate_biopsy_done = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Date_biopsy_done") 'DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Date_biopsy_done"), "01/01/1900", DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Date_biopsy_done"))
                vDate_biopsy_done = FormatDateTime(vDate_biopsy_done, DateFormat.LongDate)
                vType_Biopsy = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Type_Biopsy")
                vNeoadj_Details = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Neoadj_Details")
                vPostChemo_tum_size = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("PostChemo_tum_size")
                vPostChemo_Ax_LN = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("PostChemo_Ax_LN")
                vResponse_chemo = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Response_chemo")
                'vEnteredBy = DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("EnteredBy")

                Dim myCommand5 As SqlCommand
                Dim SqlConn5 As New SqlConnection()
                SqlConn5 = New SqlConnection(GV_CONNETION)
                myCommand = New SqlCommand("spInsertNoeAdjuvant", SqlConn5)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn5.Open()

                myCommand.Parameters.Add("@Neoadj_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@t_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@n_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@m_stage_6", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Neoadj_tum_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Date_biopsy_done", SqlDbType.DateTime)
                myCommand.Parameters.Add("@Type_Biopsy", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Neoadj_Details", SqlDbType.VarChar)
                myCommand.Parameters.Add("@PostChemo_tum_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@PostChemo_Ax_LN", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Response_chemo", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)

                'If GV_ISEDIT = True Then
                'myCommand.Parameters("@Neoadj_ID").Value = GV_SELECTED_NEOADJID
                'Else
                myCommand.Parameters("@Neoadj_ID").Value = "0"
                'End If
                myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
                myCommand.Parameters("@Event_ID").Value = vNewEventID
                myCommand.Parameters("@Histo_ID").Value = vHisto_ID
                myCommand.Parameters("@t_stage_6").Value = vt_stage_6
                myCommand.Parameters("@n_stage_6").Value = vn_stage_6
                myCommand.Parameters("@m_stage_6").Value = vm_stage_6
                myCommand.Parameters("@Neoadj_tum_size").Value = vNeoadj_tum_size
                myCommand.Parameters("@Date_biopsy_done").Value = vDate_biopsy_done 'FormatDateTime(vDate_biopsy_done, DateFormat.LongDate)
                myCommand.Parameters("@Type_Biopsy").Value = vType_Biopsy
                myCommand.Parameters("@Neoadj_Details").Value = vNeoadj_Details
                myCommand.Parameters("@PostChemo_tum_size").Value = vPostChemo_tum_size
                myCommand.Parameters("@PostChemo_Ax_LN").Value = vPostChemo_Ax_LN
                myCommand.Parameters("@Response_chemo").Value = vResponse_chemo
                myCommand.Parameters("@EnteredBy").Value = GV_USER
                myCommand.ExecuteNonQuery()

                myCommand.Cancel()
                SqlConn5.Close()
                myCommand = Nothing
                SqlConn5 = Nothing


            Else

                GV_SELECTED_NEOADJID = ""
                vNeoAdj_ID = ""
            End If


        Catch ex As Exception
            MsgBox(ex.Source)
        End Try


        'Load from PriorTx table to retrieve current neoadj_id
        Dim vPriorTX_ID1 As String = ""
        Dim vEvent_ID1 As String = ""
        Dim vPt_id2 As String = ""
        Dim vHisto_ID1 As String = ""
        Dim vPriorTxDetails1 As String = ""
        Dim vSites_Relapses1 As String = ""
        Dim vPriorTx_clin_tum_size1 As String = ""
        Dim vdate_biopsy1 As DateTime
        Dim vbiopsy_type1 As String = ""
        Dim vEnteredBy1 As String = ""
        Dim SqlConnection4 As New SqlConnection()
        Dim CNnWind1 As New SqlClient.SqlConnection(GV_CONNETION)
        SqlConnection4 = New SqlConnection(GV_CONNETION)
        If SqlConnection4.State = ConnectionState.Closed Then SqlConnection4.Open()



        Dim sqlCmd4 = New SqlCommand("select priortx_id,event_id, pt_id1,histo_id,prior_tx_details,sites_relapses, priortx_clin_tum_size,date_biopsy,biopsy_type from priortx where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection4)
        Try
            Dim DAPriorTx As New SqlClient.SqlDataAdapter("select priortx_id,event_id,pt_id1,histo_id,prior_tx_details,sites_relapses,priortx_clin_tum_size,date_biopsy,biopsy_type from priortx where Event_ID = '" & GV_SELECTED_EVENTID & "' and status <> 'D'", SqlConnection4)
            Dim DSNPriorTx = New DataSet()
            CNnWind.Open()
            DAPriorTx.Fill(DSNPriorTx, "dtTempPriorTx")
            CNnWind.Close()




            If (DSNPriorTx.Tables("dtTempPriorTx").Rows.Count > 0) Then
                GV_SELECTED_PRIOR_TREATMENT_ID = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("priortx_id")
                vPriorTX_ID1 = GV_SELECTED_PRIOR_TREATMENT_ID
                vPriorTX_ID1 = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("priortx_id")
                vEvent_ID1 = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("event_id")
                vPt_id2 = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("pt_id1")
                vHisto_ID1 = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("histo_id")
                vPriorTxDetails1 = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("prior_tx_details")
                vSites_Relapses1 = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("sites_relapses")
                vPriorTx_clin_tum_size1 = IIf(IsDBNull(DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("priortx_clin_tum_size")), "", DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("priortx_clin_tum_size"))
                vdate_biopsy1 = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("date_biopsy")
                vbiopsy_type1 = DSNPriorTx.Tables("dtTempPriorTx").Rows(0).Item("biopsy_type") 'DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Date_biopsy_done"), "01/01/1900", DSNNeoAdj.Tables("dtTempNeoAdj").Rows(0).Item("Date_biopsy_done"))


                Dim myCommand5 As SqlCommand
                Dim SqlConn5 As New SqlConnection()
                SqlConn5 = New SqlConnection(GV_CONNETION)
                myCommand = New SqlCommand("spInsertPriorTx", SqlConn5)
                myCommand.CommandType = CommandType.StoredProcedure
                SqlConn5.Open()

                myCommand.Parameters.Add("@PriorTX_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Event_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Pt_id1", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Histo_ID", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Prior_Tx_Details", SqlDbType.VarChar)
                myCommand.Parameters.Add("@Sites_Relapses", SqlDbType.VarChar)
                myCommand.Parameters.Add("@PriorTx_clin_tum_size", SqlDbType.VarChar)
                myCommand.Parameters.Add("@date_biopsy", SqlDbType.DateTime)
                myCommand.Parameters.Add("@biopsy_type", SqlDbType.VarChar)
                myCommand.Parameters.Add("@EnteredBy", SqlDbType.VarChar)


                myCommand.Parameters("@PriorTX_ID").Value = "0"
                myCommand.Parameters("@Event_ID").Value = vNewEventID
                myCommand.Parameters("@Pt_id1").Value = GV_CUR_PATID
                myCommand.Parameters("@Histo_ID").Value = vHisto_ID1
                myCommand.Parameters("@Prior_Tx_Details").Value = vPriorTxDetails1
                myCommand.Parameters("@Sites_Relapses").Value = vSites_Relapses1
                myCommand.Parameters("@PriorTx_clin_tum_size").Value = vPriorTx_clin_tum_size1
                myCommand.Parameters("@date_biopsy").Value = vdate_biopsy1
                myCommand.Parameters("@biopsy_type").Value = vbiopsy_type1
                myCommand.Parameters("@EnteredBy").Value = GV_USER
                myCommand.ExecuteNonQuery()

                myCommand.Cancel()
                SqlConn5.Close()
                myCommand = Nothing
                SqlConn5 = Nothing


            Else

                GV_SELECTED_PRIOR_TREATMENT_ID = ""
                vPriorTX_ID1 = ""
            End If


        Catch ex As Exception
            MsgBox(ex.Source)
        End Try

        MsgBox("Event: " & GV_SELECTED_EVENTID & " details for patient " & vPatID & " have been copied over to new btb date on " + FormatDateTime(DOB.Value, DateFormat.ShortDate))

        'End If


        'SqlConn.Close()
        'myCommand = Nothing
        'SqlConn = Nothing



        'If ValidateHistology() = True Then
        'SaveHistology()
        'Panel2.Enabled = False
        'Close()
        'FrmDiagnosis.Close()
        'FrmDiagnosis.Show()
        'FrmDiagnosis.Focus()
        'Else

        'End If


    End Sub

    Private Sub btnLinkedTo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLinkedTo.Click
        'display the other event details

    End Sub
End Class